Skip to content
Merged
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
200 changes: 188 additions & 12 deletions src/app/shared/services/api/folder.repo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { FolderVO, FolderVOData, ItemVO } from '@root/app/models';
import { BaseResponse, BaseRepo } from '@shared/services/api/base';
import { Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { DataStatus } from '@models/data-status.enum';
import {
convertStelaLocationToLocnVOData,
convertStelaRecordToRecordVO,
convertStelaSharetoShareVO,
convertStelaTagToTagVO,
StelaLocation,
StelaShare,
StelaTag,
type StelaRecord,
} from './record.repo';

const MIN_WHITELIST: (keyof FolderVO)[] = [
'folderId',
Expand All @@ -17,6 +27,119 @@ const DEFAULT_WHITELIST: (keyof FolderVO)[] = [
'view',
];

// This is hard coded for now as we transition away from the PHP backend.
// In future we hope to remove the need for time zone objects entirely.
export const CENTRAL_TIMEZONE_VO = {
timeZoneId: 88,
displayName: 'Central Time',
timeZonePlace: 'America/Chicago',
stdName: 'Central Standard Time',
stdAbbrev: 'CST',
stdOffset: '-06:00',
dstName: 'Central Daylight Time',
dstAbbrev: 'CDT',
dstOffset: '-05:00',
};

interface StelaFolder {
folderId: string;
size: number;
location: StelaLocation;
parentFolder: {
id: string;
};
shares: Array<StelaShare>;
tags: Array<StelaTag>;
archive: {
id: string;
name: string;
};
createdAt: string;
updatedAt: string;
description: string;
displayTimestamp: string;
displayEndTimestamp: string;
displayName: string;
downloadName: string;
imageRatio: number;
paths: {
names: string[];
};
publicAt: string;
sort: string;
thumbnailUrls: {
'200': string;
'256': string;
'500': string;
'1000': string;
'2000': string;
};
type: string;
status: string;
view: string;
children?: StelaFolderChild[];
}

interface PagedStelaResponse<T> {
items: Array<T>;
}

type StelaFolderChild = StelaFolder | StelaRecord;

const isStelaRecord = (child: StelaFolderChild): child is StelaRecord =>
child && 'recordId' in child;

const convertStelaFolderToFolderVO = (stelaFolder: StelaFolder): FolderVO => {
stelaFolder.children ??= [];
const childFolderVOs = stelaFolder.children
.filter((child): child is StelaFolder => !isStelaRecord(child))
.map(convertStelaFolderToFolderVO);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to have a limit on how deeply we recurse? I suppose not since we need folders to work all the way down. Maybe a better question is: "does this recurse all the way down the children of a folder and do we need it to do that?"

Copy link
Contributor Author

@slifty slifty Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could prevent a second layer just in defensive spirit -- but this also begs the question about the data stela returns (I assume folders in stela are shallow?)

PHP doesn't provide full depth right (i.e. our components are already assuming child folders need to be loaded?) <-- I will check.

const childRecordVOs = stelaFolder.children
.filter(isStelaRecord)
.map(convertStelaRecordToRecordVO);
return new FolderVO({
...stelaFolder,
folderId: stelaFolder.folderId,
archiveId: stelaFolder.archive.id,
displayName: stelaFolder.displayName,
displayDT: stelaFolder.displayTimestamp,
displayEndDT: stelaFolder.displayEndTimestamp,
derivedDT: stelaFolder.displayTimestamp,
derivedEndDT: stelaFolder.displayEndTimestamp,
note: '',
description: stelaFolder.description,
sort: stelaFolder.sort,
locnId: stelaFolder.location.id,
timeZoneId: 88, // Hard coded for now
view: stelaFolder.view,
imageRatio: stelaFolder.imageRatio,
type: stelaFolder.type,
thumbStatus: stelaFolder.status,
thumbURL200: stelaFolder.thumbnailUrls['200'],
thumbURL500: stelaFolder.thumbnailUrls['500'],
thumbURL1000: stelaFolder.thumbnailUrls['1000'],
thumbURL2000: stelaFolder.thumbnailUrls['2000'],
thumbDT: stelaFolder.displayTimestamp,
thumbnail256: stelaFolder.thumbnailUrls['256'],
thumbnail256CloudPath: stelaFolder.thumbnailUrls['256'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we have both of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the VO (not sure if both are actually used but I suppose therein lies the ultimate desire to move from VOs!)

public thumbnail256: string;
public thumbnail256CloudPath: string;

status: stelaFolder.status,
publicDT: stelaFolder.publicAt,
parentFolderId: stelaFolder.parentFolder.id,
pathAsText: stelaFolder.paths.names,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note to self) Plural?

ParentFolderVOs: [new FolderVO({ folderId: stelaFolder.parentFolder.id })],
ChildFolderVOs: childFolderVOs,
RecordVOs: childRecordVOs,
LocnVO: convertStelaLocationToLocnVOData(stelaFolder.location),
TimezoneVO: CENTRAL_TIMEZONE_VO,
TagVOs: (stelaFolder.tags ?? []).map((stelaTag) =>
convertStelaTagToTagVO(stelaTag, stelaFolder.archive.id),
),
ChildItemVOs: [...childRecordVOs, ...childFolderVOs],
ShareVOs: (stelaFolder.shares ?? []).map(convertStelaSharetoShareVO),
isFolder: true,
});
};

export class FolderRepo extends BaseRepo {
public async getRoot(): Promise<FolderResponse> {
return await this.http.sendRequestPromise<FolderResponse>(
Expand Down Expand Up @@ -46,20 +169,73 @@ export class FolderRepo extends BaseRepo {
);
}

private async getStelaFolder(folderVO: FolderVO): Promise<StelaFolder> {
const queryData = {
folderIds: [folderVO.folderId],
};
const folderResponse = (
await firstValueFrom(
this.httpV2.get<PagedStelaResponse<StelaFolder>>(
`v2/folder`,
queryData,
),
)
)[0];
return folderResponse.items[0];
}

private async getStelaFolderChildren(
folderVO: FolderVO,
): Promise<StelaFolderChild[]> {
const queryData = {
pageSize: 99999999, // We want all results in one request
};
const childrenResponse = (
await firstValueFrom(
this.httpV2.get<PagedStelaResponse<StelaFolderChild>>(
`v2/folder/${folderVO.folderId}/children`,
queryData,
),
)
)[0];
return childrenResponse.items;
}

public async getWithChildren(folderVOs: FolderVO[]): Promise<FolderResponse> {
const data = folderVOs.map((folderVO) => ({
FolderVO: {
archiveNbr: folderVO.archiveNbr,
folder_linkId: folderVO.folder_linkId,
folderId: folderVO.folderId,
},
}));
// Stela has two separate endpoints -- one for loading the folder, one for loading the children.
const requests = folderVOs.map(async (folderVO) => {
const stelaFolder = await this.getStelaFolder(folderVO);
const stelaFolderChildren = await this.getStelaFolderChildren(folderVO);
return {
...stelaFolder,
children: stelaFolderChildren,
};
});

return await this.http.sendRequestPromise<FolderResponse>(
'/folder/getWithChildren',
data,
{ responseClass: FolderResponse },
const stelaFolders = (await Promise.all(requests)).flat();

// We need the `Results` to look the way v1 results look, for now.
const simulatedV1FolderResponseResults = stelaFolders.map(
(stelaFolder) => ({
data: [
{
FolderVO: convertStelaFolderToFolderVO(stelaFolder),
},
],
message: ['Folder retrieved'],
status: true,
resultDT: new Date().toISOString(),
createdDT: null,
updatedDT: null,
}),
);

const folderResponse = new FolderResponse({
isSuccessful: true,
isSystemUp: true,
Results: simulatedV1FolderResponseResults,
});
return folderResponse;
}

public navigate(folderVO: FolderVO): Observable<FolderResponse> {
Expand Down
36 changes: 16 additions & 20 deletions src/app/shared/services/api/record.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FileFormat, PermanentFile } from '@models/file-vo';
import { ShareStatus } from '@models/share-vo';
import { AccessRoleType } from '@models/access-role';
import { getFirst } from '../http-v2/http-v2.service';
import { CENTRAL_TIMEZONE_VO } from './folder.repo';

class MultipartUploadUrlsList {
public urls: string[] = [];
Expand Down Expand Up @@ -52,7 +53,7 @@ class MultipartUploadUrlsList {
// to simply use what stela provides, but there is work to be done regarding
// overall type safety in this code base before we want to take that project
// on.
interface StelaTag {
export interface StelaTag {
id: string;
name: string;
type: string;
Expand All @@ -67,7 +68,7 @@ interface StelaFile {
updatedAt: string;
downloadUrl: string;
}
interface StelaLocation {
export interface StelaLocation {
id: string;
streetNumber: string;
streetName: string;
Expand All @@ -85,7 +86,7 @@ interface StelaArchive {
archiveNumber: string;
name: string;
}
interface StelaShare {
export interface StelaShare {
id: string;
status: ShareStatus;
accessRole: AccessRoleType;
Expand All @@ -95,7 +96,7 @@ interface StelaShare {
thumbUrl200: string;
};
}
type StelaRecord = Omit<RecordVO, 'files'> & {
export type StelaRecord = Omit<RecordVO, 'files'> & {
tags: Array<StelaTag> | null;
archiveNumber: string;
displayDate: string;
Expand All @@ -122,7 +123,10 @@ const resolveTagName = (tag: StelaTag): string => {
return tag.name;
};

const convertStelaTagToTagVO = (stelaTag: StelaTag, archiveId: string): TagVO =>
export const convertStelaTagToTagVO = (
stelaTag: StelaTag,
archiveId: string,
): TagVO =>
new TagVO({
tagId: Number.parseInt(stelaTag.id),
name: resolveTagName(stelaTag),
Expand All @@ -139,7 +143,7 @@ const convertStelaFileToPermanentFile = (
downloadURL: stelaFile.downloadUrl,
});

const convertStelaSharetoShareVO = (stelaShare: StelaShare): ShareVO =>
export const convertStelaSharetoShareVO = (stelaShare: StelaShare): ShareVO =>
new ShareVO({
shareId: stelaShare.id,
status: stelaShare.status,
Expand All @@ -151,7 +155,7 @@ const convertStelaSharetoShareVO = (stelaShare: StelaShare): ShareVO =>
},
});

const convertStelaLocationToLocnVOData = (
export const convertStelaLocationToLocnVOData = (
stelaLocation: StelaLocation,
): LocnVOData =>
stelaLocation.id
Expand All @@ -161,7 +165,9 @@ const convertStelaLocationToLocnVOData = (
}
: null;

const convertStelaRecordToRecordVO = (stelaRecord: StelaRecord): RecordVO =>
export const convertStelaRecordToRecordVO = (
stelaRecord: StelaRecord,
): RecordVO =>
new RecordVO({
...stelaRecord,
TagVOs: (stelaRecord.tags ?? []).map((stelaTag) =>
Expand All @@ -179,18 +185,8 @@ const convertStelaRecordToRecordVO = (stelaRecord: StelaRecord): RecordVO =>
parentFolder_linkId: stelaRecord.parentFolderLinkId,
TextDataVOs: [],
ArchiveVOs: [],
timeZoneId: 88, // Hard coded for now
TimezoneVO: {
timeZoneId: 88,
displayName: 'Central Time',
timeZonePlace: 'America/Chicago',
stdName: 'Central Standard Time',
stdAbbrev: 'CST',
stdOffset: '-06:00',
dstName: 'Central Daylight Time',
dstAbbrev: 'CDT',
dstOffset: '-05:00',
},
timeZoneId: CENTRAL_TIMEZONE_VO.timeZoneId,
TimezoneVO: CENTRAL_TIMEZONE_VO,
ShareVOs: (stelaRecord.shares ?? []).map(convertStelaSharetoShareVO),
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export class DataService {

return await Promise.resolve(true);
})
.catch((e) => {
.catch(() => {
itemRejects.forEach((reject, index) => {
items[index].fetched = null;
reject();
Expand Down