Support volumes
This commit is contained in:
@@ -3,11 +3,12 @@ import superagent from 'superagent';
|
||||
import safe from 'safetydance';
|
||||
import { sanitize } from 'pankow/utils';
|
||||
|
||||
export function createDirectoryModel(origin, accessToken, appId) {
|
||||
export function createDirectoryModel(origin, accessToken, api) {
|
||||
|
||||
return {
|
||||
name: 'DirectoryModel',
|
||||
async listFiles(path) {
|
||||
const [error, result] = await safe(superagent.get(`${origin}/api/v1/apps/${appId}/files/${path}`).query({ access_token: accessToken }));
|
||||
const [error, result] = await safe(superagent.get(`${origin}/api/v1/${api}/files/${path}`).query({ access_token: accessToken }));
|
||||
if (error) {
|
||||
console.error('Failed to list files', error);
|
||||
return [];
|
||||
@@ -17,7 +18,7 @@ export function createDirectoryModel(origin, accessToken, appId) {
|
||||
result.body.entries.forEach(item => {
|
||||
// if we have an image, attach previewUrl
|
||||
if (item.mimeType.indexOf('image/') === 0) {
|
||||
item.previewUrl = `${origin}/api/v1/apps/${appId}/files/${encodeURIComponent(path + '/' + item.fileName)}?access_token=${accessToken}`
|
||||
item.previewUrl = `${origin}/api/v1/${api}/files/${encodeURIComponent(path + '/' + item.fileName)}?access_token=${accessToken}`
|
||||
}
|
||||
|
||||
item.folderPath = path;
|
||||
@@ -26,18 +27,18 @@ export function createDirectoryModel(origin, accessToken, appId) {
|
||||
return result.body.entries;
|
||||
},
|
||||
async remove(filePath) {
|
||||
const [error] = await safe(superagent.del(`${origin}/api/v1/apps/${appId}/files/${filePath}`)
|
||||
const [error] = await safe(superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
|
||||
.query({ access_token: accessToken }));
|
||||
if (error) throw error;
|
||||
},
|
||||
async rename(fromFilePath, toFilePath) {
|
||||
const [error] = await safe(superagent.put(`${origin}/api/v1/apps/${appId}/files/${fromFilePath}`)
|
||||
const [error] = await safe(superagent.put(`${origin}/api/v1/${api}/files/${fromFilePath}`)
|
||||
.send({ action: 'rename', newFilePath: sanitize(toFilePath) })
|
||||
.query({ access_token: accessToken }));
|
||||
if (error) throw error;
|
||||
},
|
||||
async getFile(path) {
|
||||
const [error, result] = await safe(fetch(`${origin}/api/v1/apps/${appId}/files/${path}?access_token=${accessToken}`));
|
||||
const [error, result] = await safe(fetch(`${origin}/api/v1/${api}/files/${path}?access_token=${accessToken}`));
|
||||
if (error) {
|
||||
console.error('Failed to get file', error);
|
||||
return null;
|
||||
@@ -47,7 +48,7 @@ export function createDirectoryModel(origin, accessToken, appId) {
|
||||
return text;
|
||||
},
|
||||
getFileUrl(path) {
|
||||
return `${origin}/api/v1/apps/${appId}/files/${path}?access_token=${accessToken}`;
|
||||
return `${origin}/api/v1/${api}/files/${path}?access_token=${accessToken}`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user