Initial commit
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* Collection management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { FilterCondition, SortCondition } from '@/types/common';
|
||||
import type { FileCollection } from '@/types/node';
|
||||
|
||||
export const collectionService = {
|
||||
|
||||
/**
|
||||
* List collections within a location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param filter - Optional filter conditions
|
||||
* @param sort - Optional sort conditions
|
||||
* @returns Promise with collection list
|
||||
*/
|
||||
async list(
|
||||
provider: string,
|
||||
service: string,
|
||||
location?: string | null,
|
||||
filter?: FilterCondition[] | null,
|
||||
sort?: SortCondition[] | null
|
||||
): Promise<FileCollection[]> {
|
||||
return await fileManagerApi.execute<FileCollection[]>('collection.list', {
|
||||
provider,
|
||||
service,
|
||||
location: location ?? null,
|
||||
filter: filter ?? null,
|
||||
sort: sort ?? null,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a collection exists
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with extant status
|
||||
*/
|
||||
async extant(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<boolean> {
|
||||
const result = await fileManagerApi.execute<{ extant: boolean }>('collection.extant', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
return result.extant;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a specific collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with collection details
|
||||
*/
|
||||
async fetch(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.fetch', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new collection (folder)
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param data - Collection data (label, etc.)
|
||||
* @param options - Additional options
|
||||
* @returns Promise with created collection
|
||||
*/
|
||||
async create(
|
||||
provider: string,
|
||||
service: string,
|
||||
location: string | null,
|
||||
data: Partial<FileCollection>,
|
||||
options?: Record<string, unknown>
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.create', {
|
||||
provider,
|
||||
service,
|
||||
location,
|
||||
data,
|
||||
options: options ?? {},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify an existing collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @param data - Data to modify
|
||||
* @returns Promise with modified collection
|
||||
*/
|
||||
async modify(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
data: Partial<FileCollection>
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.modify', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
data,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with success status
|
||||
*/
|
||||
async destroy(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<boolean> {
|
||||
const result = await fileManagerApi.execute<{ success: boolean }>('collection.destroy', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
return result.success;
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy a collection to a new location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier to copy
|
||||
* @param location - Destination parent collection ID (null for root)
|
||||
* @returns Promise with copied collection
|
||||
*/
|
||||
async copy(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
location?: string | null
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.copy', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
location: location ?? null,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Move a collection to a new location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier to move
|
||||
* @param location - Destination parent collection ID (null for root)
|
||||
* @returns Promise with moved collection
|
||||
*/
|
||||
async move(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
location?: string | null
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.move', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
location: location ?? null,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default collectionService;
|
||||
Reference in New Issue
Block a user