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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/
import { FileKind } from '@osf/shared/enums/file-kind.enum';
import { FileMenuType } from '@osf/shared/enums/file-menu-type.enum';
import { CurrentResourceType } from '@osf/shared/enums/resource-type.enum';
import { appendDownloadTrackingParams } from '@osf/shared/helpers/download-link.helper';
import { FileTreeMapper } from '@osf/shared/mappers/files/file-tree.mapper';
import { FilesMapper } from '@osf/shared/mappers/files/files.mapper';
import { FileModel } from '@osf/shared/models/files/file.model';
Expand Down Expand Up @@ -203,13 +204,13 @@ export class FilesTreeExplorerComponent {

downloadFile(link: string): void {
if (this.isBrowser) {
window.open(link)?.focus();
window.open(appendDownloadTrackingParams(link, 'files'))?.focus();
}
}

downloadFolder(downloadLink: string): void {
if (downloadLink) {
const link = this.filesService.getFolderDownloadLink(downloadLink);
const link = this.filesService.getFolderDownloadLink(downloadLink, 'zip');
window.open(link, '_blank')?.focus();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { MetadataTabsComponent } from '@osf/shared/components/metadata-tabs/meta
import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component';
import { MetadataResourceEnum } from '@osf/shared/enums/metadata-resource.enum';
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
import { appendDownloadTrackingParams } from '@osf/shared/helpers/download-link.helper';
import { getMfrUrlWithVersion } from '@osf/shared/helpers/mfr-url.helper';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
Expand Down Expand Up @@ -250,7 +251,8 @@ export class FileDetailComponent implements OnDestroy {
const storageLink = this.file()?.links.upload || '';

if (downloadUrl) {
window.open(`${downloadUrl}/?revision=${version}`)?.focus();
const link = appendDownloadTrackingParams(`${downloadUrl}/?revision=${version}`, 'files');
window.open(link)?.focus();
this.actions.getFileRevisions(storageLink);
}
}
Expand All @@ -266,7 +268,7 @@ export class FileDetailComponent implements OnDestroy {
.logIdentifiableDownload(this.fileMetadata$)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe();
window.open(link)?.focus();
window.open(appendDownloadTrackingParams(link, 'files'))?.focus();
}

deleteEntry(link: string): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/files/pages/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class FilesComponent {
.logFileDownload(resourceId, resourcePath)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe();
const link = this.filesService.getFolderDownloadLink(downloadLink);
const link = this.filesService.getFolderDownloadLink(downloadLink, 'zip');
window.open(link, '_blank')?.focus();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ShareAndDownloadComponent {
return;
}

const downloadLink = this.socialShareService.createDownloadUrl(preprint.id);
const downloadLink = this.socialShareService.createDownloadUrl(preprint.id, 'preprint');
const downloadWindow = window.open(downloadLink);

if (!downloadWindow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PreprintDownloadRedirectComponent {
return;
}

const url = this.socialShareService.createDownloadUrl(id);
const url = this.socialShareService.createDownloadUrl(id, 'preprint');
this.redirect(url);
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/shared/helpers/download-link.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function appendDownloadTrackingParams(link: string, source: string): string {
const separator = link.includes('?') ? '&' : '?';
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
return `${link}${separator}source=${encodeURIComponent(source)}&tz=${encodeURIComponent(tz)}`;
}
5 changes: 3 additions & 2 deletions src/app/shared/services/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PaginatedData } from '@osf/shared/models/paginated-data.model';

import { FileKind } from '../enums/file-kind.enum';
import { ResourceType } from '../enums/resource-type.enum';
import { appendDownloadTrackingParams } from '../helpers/download-link.helper';
import { AddonMapper } from '../mappers/addon.mapper';
import { ContributorsMapper } from '../mappers/contributors';
import { FilesMapper } from '../mappers/files/files.mapper';
Expand Down Expand Up @@ -173,9 +174,9 @@ export class FilesService {
return this.jsonApiService.post<FileResponseJsonApi>(link, body);
}

getFolderDownloadLink(link: string): string {
getFolderDownloadLink(link: string, source: string): string {
const separator = link.includes('?') ? '&' : '?';
return `${link}${separator}zip=`;
return appendDownloadTrackingParams(`${link}${separator}zip=`, source);
}

getFileTarget(fileGuid: string): Observable<FileDetailsModel> {
Expand Down
5 changes: 3 additions & 2 deletions src/app/shared/services/social-share.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ENVIRONMENT } from '@core/provider/environment.provider';

import { SOCIAL_PLATFORMS } from '../constants/social-platforms.const';
import { SOCIAL_SHARE_URLS } from '../constants/social-share.config';
import { appendDownloadTrackingParams } from '../helpers/download-link.helper';
import { SocialShareContentModel } from '../models/socials/social-share-content.model';
import { SocialShareLinksModel } from '../models/socials/social-share-links.model';
import { SocialsShareActionItem } from '../models/socials/socials-share-action-item.model';
Expand Down Expand Up @@ -56,8 +57,8 @@ export class SocialShareService {
return `${this.webUrl}/${guid}`;
}

createDownloadUrl(resourceId: string): string {
return `${this.webUrl}/download/${resourceId}`;
createDownloadUrl(resourceId: string, source: string): string {
return appendDownloadTrackingParams(`${this.webUrl}/download/${resourceId}`, source);
}

generateSocialActionItems(content: SocialShareContentModel): SocialsShareActionItem[] {
Expand Down
Loading