feat: folder support in media library (#687)
This commit is contained in:
@ -318,7 +318,12 @@ export default class API {
|
||||
};
|
||||
};
|
||||
|
||||
listAllFiles = async (path: string, recursive = false, branch = this.branch) => {
|
||||
listAllFiles = async (
|
||||
path: string,
|
||||
folderSupport?: boolean,
|
||||
recursive = false,
|
||||
branch = this.branch,
|
||||
) => {
|
||||
const entries = [];
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { cursor, entries: initialEntries } = await this.fetchCursorAndEntries({
|
||||
@ -333,7 +338,7 @@ export default class API {
|
||||
entries.push(...newEntries);
|
||||
cursor = newCursor;
|
||||
}
|
||||
return entries.filter(({ type }) => type === 'blob');
|
||||
return entries.filter(({ type }) => (!folderSupport ? type === 'blob' : true));
|
||||
};
|
||||
|
||||
toBase64 = (str: string) => Promise.resolve(Base64.encode(str));
|
||||
@ -421,7 +426,7 @@ export default class API {
|
||||
for (const item of items.filter(i => i.oldPath && i.action === CommitAction.MOVE)) {
|
||||
const sourceDir = dirname(item.oldPath as string);
|
||||
const destDir = dirname(item.path);
|
||||
const children = await this.listAllFiles(sourceDir, true, branch);
|
||||
const children = await this.listAllFiles(sourceDir, undefined, true, branch);
|
||||
children
|
||||
.filter(f => f.path !== item.oldPath)
|
||||
.forEach(file => {
|
||||
|
@ -172,7 +172,7 @@ export default class GitLab implements BackendClass {
|
||||
}
|
||||
|
||||
async listAllFiles(folder: string, extension: string, depth: number) {
|
||||
const files = await this.api!.listAllFiles(folder, depth > 1);
|
||||
const files = await this.api!.listAllFiles(folder, undefined, depth > 1);
|
||||
const filtered = files.filter(file => this.filterFile(folder, file, extension, depth));
|
||||
return filtered;
|
||||
}
|
||||
@ -217,13 +217,13 @@ export default class GitLab implements BackendClass {
|
||||
}));
|
||||
}
|
||||
|
||||
async getMedia(mediaFolder = this.mediaFolder) {
|
||||
async getMedia(mediaFolder = this.mediaFolder, folderSupport?: boolean) {
|
||||
if (!mediaFolder) {
|
||||
return [];
|
||||
}
|
||||
return this.api!.listAllFiles(mediaFolder).then(files =>
|
||||
files.map(({ id, name, path }) => {
|
||||
return { id, name, path, displayURL: { id, name, path } };
|
||||
return this.api!.listAllFiles(mediaFolder, folderSupport).then(files =>
|
||||
files.map(({ id, name, path, type }) => {
|
||||
return { id, name, path, displayURL: { id, name, path }, isDirectory: type === 'tree' };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user