pl-api: Support Iceshrimp.NET drive

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-05-27 13:03:09 +02:00
parent 7c58922dce
commit ab600db727
5 changed files with 180 additions and 0 deletions

View File

@ -35,6 +35,8 @@ import {
credentialApplicationSchema,
customEmojiSchema,
domainBlockSchema,
driveFileSchema,
driveFolderSchema,
emojiReactionSchema,
extendedDescriptionSchema,
familiarFollowersSchema,
@ -159,6 +161,7 @@ import type {
GetChatsParams,
} from './params/chats';
import type { GetCircleStatusesParams } from './params/circles';
import type { UpdateFileParams } from './params/drive';
import type {
CreateEventParams,
EditEventParams,
@ -5596,6 +5599,119 @@ class PlApiClient {
},
};
public readonly drive = {
getDrive: async () => {
await this.#getIceshrimpAccessToken();
const response = await this.request('/api/iceshrimp/drive/folder');
return v.parse(driveFolderSchema, response.json);
},
getFolder: async (id: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/folder/${id}`);
return v.parse(driveFolderSchema, response.json);
},
createFolder: async (name: string, parentId: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request('/api/iceshrimp/drive/folder', {
method: 'POST',
body: { name, parentId },
});
return v.parse(driveFolderSchema, response.json);
},
updateFolder: async (id: string, name: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/folder/${id}`, {
method: 'PUT',
body: name,
});
return v.parse(driveFolderSchema, response.json);
},
deleteFolder: async (id: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request<{}>(`/api/iceshrimp/drive/folder/${id}`, {
method: 'DELETE',
});
return response;
},
moveFolder: async (id: string, targetFolderId: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/folder/${id}/move`, {
method: 'POST',
body: { folderId: targetFolderId },
});
return v.parse(driveFolderSchema, response.json);
},
getFile: async (id: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/${id}`);
return v.parse(driveFileSchema, response.json);
},
createFile: async (file: File, folderId: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request('/api/iceshrimp/drive', {
method: 'POST',
body: { file, folderId },
contentType: '',
});
return v.parse(driveFileSchema, response.json);
},
updateFile: async (id: string, params: UpdateFileParams) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/${id}`, {
method: 'PUT',
body: params,
});
return v.parse(driveFileSchema, response.json);
},
deleteFile: async (id: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request<{}>(`/api/iceshrimp/drive/${id}`, {
method: 'DELETE',
});
return response;
},
moveFile: async (id: string, targetFolderId: string) => {
await this.#getIceshrimpAccessToken();
const response = await this.request(`/api/iceshrimp/drive/${id}/move`, {
method: 'POST',
body: { folderId: targetFolderId },
});
return v.parse(driveFolderSchema, response.json);
},
};
/** Routes that are not part of any stable release */
public readonly experimental = {
admin: {

View File

@ -0,0 +1,29 @@
import * as v from 'valibot';
/**
* @category Schemas
*/
const driveFileSchema = v.pipe(v.any(), v.transform((file) => ({
...file,
thumbnail_url: file.thumbnailUrl,
content_type: file.contentType,
is_avatar: file.isAvatar,
is_banner: file.isBanner,
})), v.object({
id: v.string(),
url: v.string(),
thumbnail_url: v.string(),
filename: v.string(),
content_type: v.string(),
sensitive: v.boolean(),
description: v.fallback(v.nullable(v.string()), null),
is_avatar: v.boolean(),
is_banner: v.boolean(),
}));
/**
* @category Entity types
*/
type DriveFile = v.InferOutput<typeof driveFileSchema>;
export { driveFileSchema, type DriveFile };

View File

@ -0,0 +1,26 @@
import * as v from 'valibot';
import { bookmarkFolderSchema } from './bookmark-folder';
import { driveFileSchema } from './drive-file';
import { filteredArray } from './utils';
/**
* @category Schemas
*/
const driveFolderSchema = v.pipe(v.any(), v.transform((folder) => ({
...folder,
parent_id: folder.parentId,
})), v.object({
id: v.fallback(v.nullable(v.string()), null),
name: v.fallback(v.nullable(v.string()), null),
parent_id: v.fallback(v.nullable(v.string()), null),
files: filteredArray(driveFileSchema),
folders: filteredArray(bookmarkFolderSchema),
}));
/**
* @category Entity types
*/
type DriveFolder = v.InferOutput<typeof driveFolderSchema>;
export { driveFolderSchema, type DriveFolder };

View File

@ -36,6 +36,8 @@ export * from './directory/language';
export * from './directory/server';
export * from './directory/statistics-period';
export * from './domain-block';
export * from './drive-file';
export * from './drive-folder';
export * from './emoji-reaction';
export * from './extended-description';
export * from './familiar-followers';

View File

@ -0,0 +1,7 @@
interface UpdateFileParams {
filename: string;
sensitive: boolean;
description: string;
}
export type { UpdateFileParams };