PteroTheme/resources/scripts/api/server/files/loadDirectory.ts

28 lines
865 B
TypeScript
Raw Normal View History

2019-07-28 04:23:51 +01:00
import http from '@/api/http';
import { rawDataToFileObject } from '@/api/transformers';
2019-07-28 04:23:51 +01:00
export interface FileObject {
key: string;
2019-07-28 04:23:51 +01:00
name: string;
mode: string;
modeBits: string,
2019-07-28 04:23:51 +01:00
size: number;
isFile: boolean;
isSymlink: boolean;
mimetype: string;
createdAt: Date;
modifiedAt: Date;
isArchiveType: () => boolean;
isEditable: () => boolean;
2019-07-28 04:23:51 +01:00
}
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {
const { data } = await http.get(`/api/client/servers/${uuid}/files/list`, {
// At this point the directory is still encoded so we need to decode it since axios
// will automatically re-encode this value before sending it along in the request.
params: { directory: decodeURI(directory ?? '/') },
2019-07-28 04:23:51 +01:00
});
return (data.data || []).map(rawDataToFileObject);
2019-07-28 04:23:51 +01:00
};