Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/api/docs/src/models/folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ folder:
properties:
id:
type: string
archiveNumber:
type: string
size:
type: integer
location:
$ref: "../models/location.yaml#/location"
folderLinkId:
type: string
parentFolder:
type: object
properties:
id:
type: string
folderLinkId:
type: string
shares:
type: array
items:
Expand Down Expand Up @@ -87,6 +93,14 @@ folder:
type: array
items:
type: string
folderLinkIds:
type: array
items:
type: string
archiveNumbers:
type: array
items:
type: string
publicAt:
type: string
format: date-time
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/folder/controller/get_folder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ describe("GET /folder", () => {
expect(folders[0]).toBeDefined();
if (folders[0] !== undefined) {
expect(folders[0].folderId).toEqual("2");
expect(folders[0].folderLinkId).toEqual("1");
expect(folders[0].archiveNumber).toEqual("0001-0002");
expect(folders[0].size).toEqual(0);
expect(folders[0].location).toBeDefined();
if (folders[0].location !== undefined) {
Expand All @@ -219,6 +221,7 @@ describe("GET /folder", () => {
expect(folders[0].location.displayName).toEqual("Jean Valjean's House");
}
expect(folders[0].parentFolder?.id).toEqual("10");
expect(folders[0].parentFolder?.folderLinkId).toEqual("10");
expect(folders[0].shares).toBeDefined();
if (folders[0].shares !== undefined) {
expect(folders[0].shares.length).toEqual(1);
Expand Down Expand Up @@ -277,6 +280,11 @@ describe("GET /folder", () => {
expect(folders[0].paths.names.length).toEqual(2);
expect(folders[0].paths.names[0]).toEqual("My Files");
expect(folders[0].paths.names[1]).toEqual("Private Folder");
expect(folders[0].paths.folderLinkIds[0]).toEqual("10");
expect(folders[0].paths.folderLinkIds[1]).toEqual("1");
expect(folders[0].paths.archiveNumbers[0]).toEqual("0001-0010");
expect(folders[0].paths.archiveNumbers[1]).toEqual("0001-0002");
expect(folders[0].paths.names[1]).toEqual("Private Folder");
expect(folders[0].publicAt).toBeNull();
expect(folders[0].sort).toEqual("alphabetical-ascending");
expect(folders[0].thumbnailUrls).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ VALUES
NULL,
2,
10,
3,
10,
1,
1,
'access.role.owner',
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/folder/fixtures/create_test_folders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ VALUES
NULL,
'Private Folder',
'Private Folder',
NULL,
'0001-0002',
'status.generic.ok',
'2025-01-01',
'type.folder.private',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ VALUES (
),
(
4,
3,
10,
'56f7c246-e4ec-41f3-b117-6df4c9377075',
'https://local.permanent.org/share/56f7c246-e4ec-41f3-b117-6df4c9377075',
2,
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/folder/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export interface GetFolderChildrenResponse {

export interface FolderRow {
folderId: string;
archiveNumber: string;
size: string | null;
location?: Location;
parentFolder?: {
id: string;
folderLinkId: string;
};
shares?: Share[];
pendingShares: PendingShare[] | null;
Expand All @@ -39,6 +41,8 @@ export interface FolderRow {
imageRatio?: string;
paths: {
names: string[];
folderLinkIds: string[];
archiveNumbers: string[];
};
publicAt?: string;
sort: FolderSortOrder;
Expand All @@ -65,10 +69,12 @@ export interface ThumbnailUrls {

export interface Folder {
folderId: string;
archiveNumber: string;
size: number | null;
location?: Location;
parentFolder?: {
id: string;
folderLinkId: string;
};
shares?: Share[];
pendingShares: PendingShare[] | null;
Expand All @@ -88,6 +94,8 @@ export interface Folder {
imageRatio?: number;
paths: {
names: string[];
folderLinkIds: string[];
archiveNumbers: string[];
};
publicAt?: string;
sort: PrettyFolderSortOrder;
Expand Down
19 changes: 16 additions & 3 deletions packages/api/src/folder/queries/get_folders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ WITH RECURSIVE folder_path AS (
folder.folderid AS original_folder_id,
folder.folderid,
folder_link.parentfolderid,
folder_link.folder_linkid::text,
folder.displayname,
folder.archivenbr,
1 AS height
FROM folder
INNER JOIN folder_link ON folder.folderid = folder_link.folderid
Expand All @@ -15,7 +17,9 @@ WITH RECURSIVE folder_path AS (
folder_path.original_folder_id,
folder.folderid,
folder_link.parentfolderid,
folder_link.folder_linkid::text,
folder.displayname,
folder.archivenbr,
folder_path.height + 1 AS height
FROM folder_path
INNER JOIN folder_link ON folder_path.parentfolderid = folder_link.folderid
Expand All @@ -26,7 +30,9 @@ WITH RECURSIVE folder_path AS (
aggregated_path AS (
SELECT
original_folder_id AS folderid,
ARRAY_AGG(displayname ORDER BY height DESC) AS name_path
ARRAY_AGG(displayname ORDER BY height DESC) AS name_path,
ARRAY_AGG(archivenbr ORDER BY height DESC) AS archive_number_path,
ARRAY_AGG(folder_linkid ORDER BY height DESC) AS folder_link_id_path
FROM folder_path
GROUP BY
original_folder_id
Expand Down Expand Up @@ -207,6 +213,7 @@ account_by_share AS (

SELECT
folder.folderid AS "folderId",
folder.archivenbr AS "archiveNumber",
folder_size.allfilesizedeep AS size,
aggregated_shares.folder_shares AS shares,
aggregated_tags.tags,
Expand Down Expand Up @@ -281,7 +288,9 @@ SELECT
) AS location,
JSON_BUILD_OBJECT(
'id',
folder_link.parentfolderid::text
folder_link.parentfolderid::text,
'folderLinkId',
folder_link.parentfolder_linkid::text
) AS "parentFolder",
JSON_BUILD_OBJECT(
'id',
Expand All @@ -291,7 +300,11 @@ SELECT
) AS archive,
JSONB_BUILD_OBJECT(
'names',
aggregated_path.name_path
aggregated_path.name_path,
'folderLinkIds',
aggregated_path.folder_link_id_path,
'archiveNumbers',
aggregated_path.archive_number_path
) AS paths,
JSON_BUILD_OBJECT(
'200',
Expand Down