127 lines
3.6 KiB
TypeScript
127 lines
3.6 KiB
TypeScript
import { apiWrapper, boolApiWrapper } from './index'
|
|||
|
|
|
||
|
|
type Uuid = string;
|
||
|
|
|
||
|
|
// Collection item interface
|
||
|
|
interface CollectionItem {
|
||
|
|
uuid: Uuid
|
||
|
|
name: string
|
||
|
|
lastChange: string
|
||
|
|
}
|
||
|
|
|
||
|
|
// Sharing info interface
|
||
|
|
interface SharingInfo {
|
||
|
|
target: string
|
||
|
|
// Add other sharing-related fields as needed
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get all owned collections
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @returns Array of collection items or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function getFullOwn(token: string): Promise<CollectionItem[] | undefined> {
|
||
|
|
return apiWrapper('/api/collection/getFullOwn', { token });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get owned collection detail by UUID
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @returns Collection item or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function getDetailOwn(token: string, uuid: Uuid): Promise<CollectionItem | undefined> {
|
||
|
|
return apiWrapper('/api/collection/getDetailOwn', { token, uuid });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Add new owned collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param name - Collection name
|
||
|
|
* @returns Created collection item or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function addOwn(token: string, name: string): Promise<Uuid | undefined> {
|
||
|
|
return apiWrapper('/api/collection/addOwn', { token, name });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update owned collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @param name - New name
|
||
|
|
* @param lastChange - Last change timestamp
|
||
|
|
* @returns Updated collection item or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function updateOwn(
|
||
|
|
token: string,
|
||
|
|
uuid: Uuid,
|
||
|
|
name: string,
|
||
|
|
lastChange: string
|
||
|
|
): Promise<CollectionItem | undefined> {
|
||
|
|
return apiWrapper('/api/collection/updateOwn', { token, uuid, name, lastChange });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Delete owned collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @param lastChange - Last change timestamp
|
||
|
|
* @returns true if deletion successful, false otherwise
|
||
|
|
*/
|
||
|
|
export async function deleteOwn(token: string, uuid: Uuid, lastChange: string): Promise<boolean> {
|
||
|
|
return boolApiWrapper('/api/collection/deleteOwn', { token, uuid, lastChange });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get sharing information for a collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @returns Array of sharing info or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function getSharing(token: string, uuid: Uuid): Promise<SharingInfo[] | undefined> {
|
||
|
|
return apiWrapper('/api/collection/getSharing', { token, uuid });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Delete sharing for a collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @param target - Target user
|
||
|
|
* @param lastChange - Last change timestamp
|
||
|
|
* @returns Result data or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function deleteSharing(
|
||
|
|
token: string,
|
||
|
|
uuid: Uuid,
|
||
|
|
target: string,
|
||
|
|
lastChange: string
|
||
|
|
): Promise<any | undefined> {
|
||
|
|
return apiWrapper('/api/collection/deleteSharing', { token, uuid, target, lastChange });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Add sharing for a collection
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @param uuid - Collection UUID
|
||
|
|
* @param target - Target user
|
||
|
|
* @param lastChange - Last change timestamp
|
||
|
|
* @returns Result data or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function addSharing(
|
||
|
|
token: string,
|
||
|
|
uuid: Uuid,
|
||
|
|
target: string,
|
||
|
|
lastChange: string
|
||
|
|
): Promise<any | undefined> {
|
||
|
|
return apiWrapper('/api/collection/addSharing', { token, uuid, target, lastChange });
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get all shared collections
|
||
|
|
* @param token - Authentication token
|
||
|
|
* @returns Array of collection items or null if operation failed
|
||
|
|
*/
|
||
|
|
export async function getShared(token: string): Promise<CollectionItem[] | undefined> {
|
||
|
|
return apiWrapper('/api/collection/getShared', { token });
|
||
|
|
}
|