Skip to content

Commit

Permalink
Add support for IPFS multihash urls in file info dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
floogulinc committed Oct 9, 2022
1 parent 056aa2b commit b90a307
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/app/file-info-sheet/file-info-sheet.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ <h2 mat-dialog-title class="sheet-title">File Info</h2>
<mat-icon>link</mat-icon>
<span>Copy hyshare URL</span>
</button>
<button mat-menu-item *ngIf="ipfsUrl$ | async as ipfsUrl" [cdkCopyToClipboard]="ipfsUrl">
<mat-icon>link</mat-icon>
<span>Copy IPFS URL</span>
</button>
<button mat-menu-item (click)="reload()">
<mat-icon>refresh</mat-icon>
<span>Refresh</span>
Expand Down
7 changes: 6 additions & 1 deletion src/app/file-info-sheet/file-info-sheet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { saveAs } from 'file-saver';
import { MatSnackBar } from '@angular/material/snack-bar';
import { tagsObjectFromFile } from '../utils/tag-utils';
import { SettingsService } from '../settings.service';
import { BehaviorSubject, map, shareReplay, switchMap } from 'rxjs';
import { BehaviorSubject, filter, map, shareReplay, switchMap } from 'rxjs';

interface ShareData {
title?: string;
Expand Down Expand Up @@ -76,6 +76,11 @@ export class FileInfoSheetComponent {
shareReplay(1),
)

ipfsUrl$ = this.file$.pipe(
filter(file => file.ipfs_multihashes && Object.values(file.ipfs_multihashes).length > 0),
map(file => `${this.settings.appSettings.ipfsMultihashUrlPrefix}${Object.values(file.ipfs_multihashes)[0]}`)
)


reload() {
this.reload$.next(null);
Expand Down
2 changes: 2 additions & 0 deletions src/app/hydrus-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface HydrusFileFromAPI extends HydrusBasicFileFromAPI {
notes?: HydrusNotes;

detailed_known_urls?: HydrusURLInfo[];

ipfs_multihashes?: Record<string, string>;
}

export interface HydrusFile extends HydrusFileFromAPI, HydrusBasicFile {
Expand Down
4 changes: 3 additions & 1 deletion src/app/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface AppSettingsV1 {
hyshareUrl: string;
saucenaoApiKey: string;
saucenaoSearchProxy: string;
ipfsMultihashUrlPrefix: string;
}

export type AppSettingsStorage = AppSettingsV1;
Expand All @@ -20,5 +21,6 @@ export const defaultAppSettings: AppSettings = {
browseDefaultSearchTags: [],
hyshareUrl: '',
saucenaoApiKey: '',
saucenaoSearchProxy: '/__saucenao-search'
saucenaoSearchProxy: '/__saucenao-search',
ipfsMultihashUrlPrefix: 'https://ipfs.io/ipfs/'
}
9 changes: 7 additions & 2 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>SauceNAO API Key</mat-label>
<mat-label>IPFS multihash URL prefix</mat-label>
<input matInput type="url" autocomplete="off" formControlName="ipfsMultihashUrlPrefix">
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>SauceNAO API key</mat-label>
<input matInput type="password" autocomplete="off" formControlName="saucenaoApiKey">
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>SauceNAO Search Proxy URL</mat-label>
<mat-label>SauceNAO search proxy URL</mat-label>
<input matInput type="text" autocomplete="off" formControlName="saucenaoSearchProxy">
</mat-form-field>
<div fxLayout="row wrap" fxLayoutAlign="end" class="">
Expand Down

0 comments on commit b90a307

Please sign in to comment.