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
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export class FileDetailComponent {
this.actions.getFileResourceMetadata(this.resourceId, this.resourceType);
this.actions.getFileResourceContributors(this.resourceId, this.resourceType);
if (fileId) {
const fileProvider = this.file()?.provider || '';
this.actions.getFileRevisions(this.resourceId, fileProvider, fileId);
const storageLink = this.file()?.links.download || '';
this.actions.getFileRevisions(storageLink, fileId);
this.actions.getCedarTemplates();
this.actions.getCedarRecords(fileId, ResourceType.File);
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/features/files/pages/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class FilesComponent {
effect(() => {
const rootFolders = this.rootFolders();
if (rootFolders) {
const osfRootFolder = rootFolders.find((folder: OsfFile) => folder.provider === 'osfstorage');
const osfRootFolder = rootFolders.find((folder: OsfFile) => folder.provider === FileProvider.OsfStorage);
if (osfRootFolder) {
this.currentRootFolder.set({
label: this.translateService.instant('files.storageLocation'),
Expand Down Expand Up @@ -334,14 +334,14 @@ export class FilesComponent {
const resourceId = this.resourceId();
const folderId = this.currentFolder()?.id ?? '';
const isRootFolder = !this.currentFolder()?.relationships?.parentFolderLink;
const provider = this.currentRootFolder()?.folder?.provider ?? 'osfstorage';
const storageLink = this.currentRootFolder()?.folder?.links?.download ?? '';

if (resourceId && folderId) {
if (isRootFolder) {
const link = this.filesService.getFolderDownloadLink(resourceId, provider, '', true);
const link = this.filesService.getFolderDownloadLink(storageLink, '', true);
window.open(link, '_blank')?.focus();
} else {
const link = this.filesService.getFolderDownloadLink(resourceId, provider, folderId, false);
const link = this.filesService.getFolderDownloadLink(storageLink, folderId, false);
window.open(link, '_blank')?.focus();
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ export class FilesComponent {
}

getAddonName(addons: ConfiguredAddonModel[], provider: string): string {
if (provider === 'osfstorage') {
if (provider === FileProvider.OsfStorage) {
return this.translateService.instant('files.storageLocation');
} else {
return addons.find((addon) => addon.externalServiceName === provider)?.displayName ?? '';
Expand Down
3 changes: 1 addition & 2 deletions src/app/features/files/store/files.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export class GetFileRevisions {
static readonly type = '[Files] Get Revisions';

constructor(
public resourceId: string,
public fileProvider: string,
public link: string,
public fileId: string
) {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/files/store/files.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class FilesState {
const state = ctx.getState();
ctx.patchState({ fileRevisions: { ...state.fileRevisions, isLoading: true, error: null } });

return this.filesService.getFileRevisions(action.resourceId, action.fileProvider, action.fileId).pipe(
return this.filesService.getFileRevisions(action.link, action.fileId).pipe(
tap({
next: (revisions) => {
ctx.patchState({ fileRevisions: { data: revisions, isLoading: false, error: null } });
Expand Down
5 changes: 3 additions & 2 deletions src/app/shared/components/files-tree/files-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,13 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {

downloadFolder(folderId: string, rootFolder: boolean): void {
const resourceId = this.resourceId();
const storageLink = this.currentFolder()?.links?.download ?? '';
if (resourceId && folderId) {
if (rootFolder) {
const link = this.filesService.getFolderDownloadLink(resourceId, this.provider()!, '', true);
const link = this.filesService.getFolderDownloadLink(storageLink, '', true);
window.open(link, '_blank')?.focus();
} else {
const link = this.filesService.getFolderDownloadLink(resourceId, this.provider()!, folderId, false);
const link = this.filesService.getFolderDownloadLink(storageLink, folderId, false);
window.open(link, '_blank')?.focus();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/mappers/files/files.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function MapFile(
move: file.links?.move,
upload: file.links?.upload,
delete: file.links?.delete,
download: file.links?.download,
download: file.attributes.kind === 'folder' ? file.links.upload : file.links?.download,
self: file.links?.self,
html: file.links?.html,
render: file.links?.render,
Expand Down
12 changes: 5 additions & 7 deletions src/app/shared/services/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ export class FilesService {
);
}

getFolderDownloadLink(resourceId: string, provider: string, folderId: string, isRootFolder: boolean): string {
getFolderDownloadLink(storageLink: string, folderId: string, isRootFolder: boolean): string {
if (isRootFolder) {
return `${environment.fileApiUrl}/resources/${resourceId}/providers/${provider}/?zip=`;
return `${storageLink}?zip=`;
}
return `${environment.fileApiUrl}/resources/${resourceId}/providers/${provider}/${folderId}/?zip=`;
return `${storageLink}${folderId}/?zip=`;
}

getFileTarget(fileGuid: string): Observable<OsfFile> {
Expand Down Expand Up @@ -248,11 +248,9 @@ export class FilesService {
.pipe(map((response) => MapFileCustomMetadata(response)));
}

getFileRevisions(resourceId: string, provider: string, fileId: string): Observable<OsfFileRevision[]> {
getFileRevisions(link: string, fileId: string): Observable<OsfFileRevision[]> {
return this.jsonApiService
.get<GetFileRevisionsResponse>(
`${environment.fileApiUrl}/resources/${resourceId}/providers/${provider}/${fileId}?revisions=`
)
.get<GetFileRevisionsResponse>(`${link}/${fileId}?revisions=`)
.pipe(map((response) => MapFileRevision(response.data)));
}

Expand Down
4 changes: 0 additions & 4 deletions src/environments/environment.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export const environment = {
* URL for the OSF Addons API (v1).
*/
addonsApiUrl: 'https://addons.staging4.osf.io/v1',
/**
* URL for file-related operations on the US storage region.
*/
fileApiUrl: 'https://files.us.staging4.osf.io/v1',
/**
* API endpoint for funder metadata resolution via Crossref.
*/
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.test-osf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const environment = {
apiDomainUrl: 'https://api.test.osf.io',
shareTroveUrl: 'https://test-share.osf.io/trove',
addonsApiUrl: 'https://addons.test.osf.io/v1',
fileApiUrl: 'https://files.us.test.osf.io/v1',
funderApiUrl: 'https://api.crossref.org/',
casUrl: 'https://accounts.test.osf.io',
recaptchaSiteKey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
Expand Down
4 changes: 0 additions & 4 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export const environment = {
* URL for the OSF Addons API (v1).
*/
addonsApiUrl: 'https://addons.staging4.osf.io/v1',
/**
* URL for file-related operations on the US storage region.
*/
fileApiUrl: 'https://files.us.staging4.osf.io/v1',
/**
* API endpoint for funder metadata resolution via Crossref.
*/
Expand Down
Loading