mirror of
https://github.com/CaramelFur/Picsur.git
synced 2026-05-06 09:55:48 +02:00
add frontend apikey service
This commit is contained in:
@@ -78,6 +78,13 @@ export class ApiService {
|
||||
});
|
||||
}
|
||||
|
||||
public async postEmpty<T extends z.AnyZodObject>(
|
||||
type: ZodDtoStatic<T>,
|
||||
url: string,
|
||||
): AsyncFailable<z.infer<T>> {
|
||||
return this.fetchSafeJson(type, url, { method: 'POST' });
|
||||
}
|
||||
|
||||
public async postForm<T extends z.AnyZodObject>(
|
||||
receiveType: ZodDtoStatic<T>,
|
||||
url: string,
|
||||
|
||||
68
frontend/src/app/services/api/apikeys.service.ts
Normal file
68
frontend/src/app/services/api/apikeys.service.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
ApiKeyCreateResponse,
|
||||
ApiKeyDeleteRequest,
|
||||
ApiKeyDeleteResponse,
|
||||
ApiKeyInfoRequest,
|
||||
ApiKeyInfoResponse,
|
||||
ApiKeyListRequest,
|
||||
ApiKeyListResponse
|
||||
} from 'picsur-shared/dist/dto/api/apikeys.dto';
|
||||
import { EApiKey } from 'picsur-shared/dist/entities/apikey.entity';
|
||||
import { AsyncFailable, Open } from 'picsur-shared/dist/types';
|
||||
import { ApiService } from './api.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ApiKeysService {
|
||||
constructor(private readonly api: ApiService) {}
|
||||
|
||||
public async getApiKeys(
|
||||
count: number,
|
||||
page: number,
|
||||
userID?: string,
|
||||
): AsyncFailable<EApiKey[]> {
|
||||
const response = await this.api.post(
|
||||
ApiKeyListRequest,
|
||||
ApiKeyListResponse,
|
||||
'/api/apikeys/list',
|
||||
{
|
||||
count,
|
||||
page,
|
||||
user_id: userID,
|
||||
},
|
||||
);
|
||||
|
||||
return Open(response, 'results');
|
||||
}
|
||||
|
||||
public async getApiKey(key: string): AsyncFailable<EApiKey> {
|
||||
return await this.api.post(
|
||||
ApiKeyInfoRequest,
|
||||
ApiKeyInfoResponse,
|
||||
'/api/apikeys/info',
|
||||
{
|
||||
key,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public async createApiKey(): AsyncFailable<EApiKey> {
|
||||
return await this.api.postEmpty(
|
||||
ApiKeyCreateResponse,
|
||||
'/api/apikeys/create',
|
||||
);
|
||||
}
|
||||
|
||||
public async deleteApiKey(key: string): AsyncFailable<EApiKey> {
|
||||
return await this.api.post(
|
||||
ApiKeyDeleteRequest,
|
||||
ApiKeyDeleteResponse,
|
||||
'/api/apikeys/delete',
|
||||
{
|
||||
key,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user