feat(jslib): getRaw can return authenticated url

This commit is contained in:
Tomáš Mládek 2024-04-08 21:40:14 +02:00
parent 49420e53c2
commit 143a2c8ad2
2 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@upnd/upend",
"version": "0.5.2",
"version": "0.5.3",
"description": "Client library to interact with the UpEnd system.",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View file

@ -231,8 +231,15 @@ export class UpEndApi {
});
}
public getRaw(address: Address, preview = false) {
return `${this.apiUrl}/${preview ? "thumb" : "raw"}/${address}`;
public getRaw(
address: Address,
config?: { preview?: boolean; authenticated?: boolean },
) {
let result = `${this.apiUrl}/${config?.preview ? "thumb" : "raw"}/${address}`;
if (config?.authenticated) {
result += `?key=${this.key}`;
}
return result;
}
public async fetchRaw(
@ -241,7 +248,7 @@ export class UpEndApi {
options?: ApiFetchOptions,
) {
dbg("Getting %s raw (preview = %s)", address, preview);
return await this.fetch(this.getRaw(address, preview), options);
return await this.fetch(this.getRaw(address, { preview }), options);
}
public async refreshVault(options?: ApiFetchOptions) {