pl-api: support Iceshrimp.NET drive updates
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -41,6 +41,7 @@ import {
|
||||
domainBlockSchema,
|
||||
driveFileSchema,
|
||||
driveFolderSchema,
|
||||
driveStatusSchema,
|
||||
emojiReactionSchema,
|
||||
extendedDescriptionSchema,
|
||||
familiarFollowersSchema,
|
||||
@ -6012,6 +6013,14 @@ class PlApiClient {
|
||||
|
||||
return v.parse(driveFileSchema, response.json);
|
||||
},
|
||||
|
||||
getDriveStatus: async () => {
|
||||
await this.#getIceshrimpAccessToken();
|
||||
|
||||
const response = await this.request('/api/iceshrimp/drive/status');
|
||||
|
||||
return v.parse(driveStatusSchema, response.json);
|
||||
},
|
||||
};
|
||||
|
||||
public readonly stories = {
|
||||
|
||||
@ -3,11 +3,18 @@ import * as v from 'valibot';
|
||||
import { type DriveFile, driveFileSchema } from './drive-file';
|
||||
import { filteredArray } from './utils';
|
||||
|
||||
const drivePathEntrySchema = 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),
|
||||
});
|
||||
|
||||
const baseDriveFolderSchema = 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),
|
||||
path: filteredArray(drivePathEntrySchema),
|
||||
});
|
||||
|
||||
/**
|
||||
@ -16,6 +23,10 @@ const baseDriveFolderSchema = v.object({
|
||||
const driveFolderSchema: v.BaseSchema<any, DriveFolder, v.BaseIssue<unknown>> = v.pipe(v.any(), v.transform((folder) => ({
|
||||
...folder,
|
||||
parent_id: folder.parentId,
|
||||
path: folder.path?.map((entry: any) => ({
|
||||
...entry,
|
||||
parent_id: entry.parentId,
|
||||
})),
|
||||
})), v.object({
|
||||
...baseDriveFolderSchema.entries,
|
||||
folders: filteredArray(v.lazy(() => driveFolderSchema)),
|
||||
|
||||
20
packages/pl-api/lib/entities/drive-status.ts
Normal file
20
packages/pl-api/lib/entities/drive-status.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as v from 'valibot';
|
||||
|
||||
/**
|
||||
* @category Schemas
|
||||
*/
|
||||
const driveStatusSchema = v.pipe(v.any(), v.transform((status) => ({
|
||||
file_count: status.fileCount,
|
||||
used_size: status.usedSize,
|
||||
...status,
|
||||
})), v.object({
|
||||
file_count: v.fallback(v.number(), 0),
|
||||
used_size: v.fallback(v.number(), 0),
|
||||
}));
|
||||
|
||||
/**
|
||||
* @category Entity types
|
||||
*/
|
||||
type DriveStatus = v.InferOutput<typeof driveStatusSchema>;
|
||||
|
||||
export { driveStatusSchema, type DriveStatus };
|
||||
@ -40,6 +40,7 @@ export * from './directory/statistics-period';
|
||||
export * from './domain-block';
|
||||
export * from './drive-file';
|
||||
export * from './drive-folder';
|
||||
export * from './drive-status';
|
||||
export * from './emoji-reaction';
|
||||
export * from './extended-description';
|
||||
export * from './familiar-followers';
|
||||
|
||||
Reference in New Issue
Block a user