Skip to content

Commit

Permalink
feat(server): add generic url upload provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pl4nty authored Sep 3, 2023
1 parent da2ae29 commit 334a514
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions server/providers/uploads/url/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Provider } from '../../../uploads/provider'

interface UrlProviderOptions {
templateUrl: string;
}

// assumes URL will always resolve to a file
// uploaders should interact with the storage provider directly
export default class UrlProvider implements Provider {
private templateUrl: string

constructor (_options: Partial<UrlProviderOptions>) {
const options: Required<UrlProviderOptions> = {
templateUrl: _options.templateUrl || 'https://storageaccount.blob.core.windows.net/uploads/{{name}}'
}

this.templateUrl = options.templateUrl
}

upload = async (data: Buffer): Promise<string> => data.toString()
getUrl = async (sha256: string, name: string): Promise<string|null> => this.templateUrl
.replace('{{sha256}}', sha256)
.replace('{{name}}', name)
}

0 comments on commit 334a514

Please sign in to comment.