forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDirectoryContents.ts
More file actions
40 lines (36 loc) · 1.48 KB
/
getDirectoryContents.ts
File metadata and controls
40 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import http from '../http';
import {filter, isObject} from 'lodash';
import {DirectoryContentObject, DirectoryContents} from "./types";
/**
* Get the contents of a specific directory for a given server.
*/
export function getDirectoryContents(server: string, directory: string): Promise<DirectoryContents> {
return new Promise((resolve, reject) => {
http.get(`/api/client/servers/${server}/files/list`, {
params: {directory}
})
.then((response) => {
return resolve({
files: filter(response.data.contents, function (o: DirectoryContentObject) {
return o.file;
}),
directories: filter(response.data.contents, function (o: DirectoryContentObject) {
return o.directory;
}),
editable: response.data.editable,
});
})
.catch(err => {
if (err.response && err.response.status === 404) {
return reject('The directory you requested could not be located on the server');
}
if (err.response.data && isObject(err.response.data.errors)) {
err.response.data.errors.forEach((error: any) => {
return reject(error.detail);
});
}
return reject(err);
});
});
}
export default getDirectoryContents;