From f64e7721455f5faea9ab6d991d76230c6062bc94 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Sat, 25 Jul 2020 15:36:09 -0700 Subject: [PATCH] added hmac auth to report route Co-authored-by: timvisee --- app/api.js | 5 ++++- app/fileReceiver.js | 6 +++++- app/serviceWorker.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/api.js b/app/api.js index fd29db77..a36d2228 100644 --- a/app/api.js +++ b/app/api.js @@ -61,7 +61,10 @@ async function fetchWithAuth(url, params, keychain) { const result = {}; params = params || {}; const h = await keychain.authHeader(); - params.headers = new Headers({ Authorization: h }); + params.headers = new Headers({ + Authorization: h, + 'Content-Type': 'application/json' + }); const response = await fetch(url, params); result.response = response; result.ok = response.ok; diff --git a/app/fileReceiver.js b/app/fileReceiver.js index 262b19e1..7c2e368b 100644 --- a/app/fileReceiver.js +++ b/app/fileReceiver.js @@ -1,7 +1,7 @@ import Nanobus from 'nanobus'; import Keychain from './keychain'; import { delay, bytes, streamToArrayBuffer } from './utils'; -import { downloadFile, metadata, getApiUrl } from './api'; +import { downloadFile, metadata, getApiUrl, reportLink } from './api'; import { blobStream } from './streams'; import Zip from './zip'; @@ -53,6 +53,10 @@ export default class FileReceiver extends Nanobus { this.state = 'ready'; } + async reportLink(reason) { + await reportLink(this.fileInfo.id, this.keychain, reason); + } + sendMessageToSw(msg) { return new Promise((resolve, reject) => { const channel = new MessageChannel(); diff --git a/app/serviceWorker.js b/app/serviceWorker.js index bc824e2d..34ae25b2 100644 --- a/app/serviceWorker.js +++ b/app/serviceWorker.js @@ -9,7 +9,7 @@ import contentDisposition from 'content-disposition'; let noSave = false; const map = new Map(); const IMAGES = /.*\.(png|svg|jpg)$/; -const VERSIONED_ASSET = /\.[A-Fa-f0-9]{8}\.(js|css|png|svg|jpg)$/; +const VERSIONED_ASSET = /\.[A-Fa-f0-9]{8}\.(js|css|png|svg|jpg)(#\w+)?$/; const DOWNLOAD_URL = /\/api\/download\/([A-Fa-f0-9]{4,})/; const FONT = /\.woff2?$/;