more robust recursive folder check
All checks were successful
Lint / pnpm_install (pull_request) Successful in 1m51s
Publish Docker image / Build (pull_request) Successful in 4m34s
Test (production install and build) / production (20.16.0) (pull_request) Successful in 1m4s
Lint / lint (backend) (pull_request) Successful in 2m11s
Test (backend) / unit (20.16.0) (pull_request) Successful in 6m58s
Lint / lint (frontend) (pull_request) Successful in 2m20s
Lint / lint (frontend-embed) (pull_request) Successful in 2m23s
Test (backend) / e2e (20.16.0) (pull_request) Successful in 10m29s
Lint / lint (frontend-shared) (pull_request) Successful in 2m23s
Lint / lint (misskey-bubble-game) (pull_request) Successful in 2m22s
Lint / lint (misskey-js) (pull_request) Successful in 2m13s
Lint / lint (misskey-reversi) (pull_request) Successful in 2m29s
Lint / lint (sw) (pull_request) Successful in 2m28s
Lint / typecheck (backend) (pull_request) Successful in 2m17s
Lint / typecheck (misskey-js) (pull_request) Successful in 1m46s
Lint / typecheck (sw) (pull_request) Successful in 1m48s
All checks were successful
Lint / pnpm_install (pull_request) Successful in 1m51s
Publish Docker image / Build (pull_request) Successful in 4m34s
Test (production install and build) / production (20.16.0) (pull_request) Successful in 1m4s
Lint / lint (backend) (pull_request) Successful in 2m11s
Test (backend) / unit (20.16.0) (pull_request) Successful in 6m58s
Lint / lint (frontend) (pull_request) Successful in 2m20s
Lint / lint (frontend-embed) (pull_request) Successful in 2m23s
Test (backend) / e2e (20.16.0) (pull_request) Successful in 10m29s
Lint / lint (frontend-shared) (pull_request) Successful in 2m23s
Lint / lint (misskey-bubble-game) (pull_request) Successful in 2m22s
Lint / lint (misskey-js) (pull_request) Successful in 2m13s
Lint / lint (misskey-reversi) (pull_request) Successful in 2m29s
Lint / lint (sw) (pull_request) Successful in 2m28s
Lint / typecheck (backend) (pull_request) Successful in 2m17s
Lint / typecheck (misskey-js) (pull_request) Successful in 1m46s
Lint / typecheck (sw) (pull_request) Successful in 1m48s
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
7a106a390d
commit
82f4277673
3 changed files with 15 additions and 9 deletions
|
@ -30,7 +30,8 @@ export class DriveFolderEntityService {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: MiDriveFolder['id'] | MiDriveFolder,
|
src: MiDriveFolder['id'] | MiDriveFolder,
|
||||||
options?: {
|
options?: {
|
||||||
detail: boolean
|
detail: boolean,
|
||||||
|
maxDepth?: number,
|
||||||
},
|
},
|
||||||
): Promise<Packed<'DriveFolder'>> {
|
): Promise<Packed<'DriveFolder'>> {
|
||||||
const opts = Object.assign({
|
const opts = Object.assign({
|
||||||
|
@ -55,7 +56,8 @@ export class DriveFolderEntityService {
|
||||||
|
|
||||||
...(folder.parentId ? {
|
...(folder.parentId ? {
|
||||||
parent: this.pack(folder.parentId, {
|
parent: this.pack(folder.parentId, {
|
||||||
detail: true,
|
detail: (options?.maxDepth ? options.maxDepth > 0 : true),
|
||||||
|
maxDepth: options?.maxDepth || 32,
|
||||||
}),
|
}),
|
||||||
} : {}),
|
} : {}),
|
||||||
} : {}),
|
} : {}),
|
||||||
|
|
|
@ -32,7 +32,7 @@ export const meta = {
|
||||||
},
|
},
|
||||||
|
|
||||||
recursiveNesting: {
|
recursiveNesting: {
|
||||||
message: 'It can not be structured like nesting folders recursively.',
|
message: 'Folders are linked recursively or too deeply.',
|
||||||
code: 'RECURSIVE_NESTING',
|
code: 'RECURSIVE_NESTING',
|
||||||
id: 'dbeb024837894013aed44279f9199740',
|
id: 'dbeb024837894013aed44279f9199740',
|
||||||
},
|
},
|
||||||
|
@ -94,7 +94,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the circular reference will occur
|
// Check if the circular reference will occur
|
||||||
const checkCircle = async (folderId: string): Promise<boolean> => {
|
const checkCircle = async (folderId: string, limit: number = 32): Promise<boolean> => {
|
||||||
|
if (limit <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const folder2 = await this.driveFoldersRepository.findOneByOrFail({
|
const folder2 = await this.driveFoldersRepository.findOneByOrFail({
|
||||||
id: folderId,
|
id: folderId,
|
||||||
});
|
});
|
||||||
|
@ -102,7 +105,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
if (folder2.id === folder.id) {
|
if (folder2.id === folder.id) {
|
||||||
return true;
|
return true;
|
||||||
} else if (folder2.parentId) {
|
} else if (folder2.parentId) {
|
||||||
return await checkCircle(folder2.parentId);
|
return await checkCircle(folder2.parentId, limit - 1);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -927,14 +927,15 @@ describe('Endpoints', () => {
|
||||||
const folderC = (await api('drive/folders/create', {
|
const folderC = (await api('drive/folders/create', {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
}, alice)).body;
|
}, alice)).body;
|
||||||
await api('drive/folders/update', {
|
assert.ok(folderA.id && folderB.id && folderC.id);
|
||||||
|
assert.strictEqual((await api('drive/folders/update', {
|
||||||
folderId: folderB.id,
|
folderId: folderB.id,
|
||||||
parentId: folderA.id,
|
parentId: folderA.id,
|
||||||
}, alice);
|
}, alice)).status, 200);
|
||||||
await api('drive/folders/update', {
|
assert.strictEqual((await api('drive/folders/update', {
|
||||||
folderId: folderC.id,
|
folderId: folderC.id,
|
||||||
parentId: folderB.id,
|
parentId: folderB.id,
|
||||||
}, alice);
|
}, alice)).status, 200);
|
||||||
|
|
||||||
const res = await api('drive/folders/update', {
|
const res = await api('drive/folders/update', {
|
||||||
folderId: folderA.id,
|
folderId: folderA.id,
|
||||||
|
|
Loading…
Reference in a new issue