Skip to content

Commit

Permalink
fix: allow public files read
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrvis committed Dec 21, 2023
1 parent 3b6c5c6 commit a4c8587
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/api/akord-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default class AkordApi extends Api {
const { response } = await new ApiClient()
.env(this.config)
.resourceId(id)
.public(options.public)
.progressHook(options.progressHook)
.cancelHook(options.cancelHook)
.downloadFile();
Expand Down
6 changes: 4 additions & 2 deletions src/core/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FileService extends Service {
}

public async download(fileUri: string, options: FileChunkedGetOptions = { responseType: 'arraybuffer' }): Promise<ReadableStream<Uint8Array> | ArrayBuffer> {
const file = await this.api.downloadFile(fileUri, { responseType: 'stream' });
const file = await this.api.downloadFile(fileUri, { responseType: 'stream', public: this.isPublic });
let stream: ReadableStream<Uint8Array>;
if (this.isPublic) {
stream = file.fileData as ReadableStream<Uint8Array>;
Expand Down Expand Up @@ -221,7 +221,8 @@ class FileService extends Service {
if (!options.cacheOnly) {
const uri = chunkedResource.resourceLocation.split(":")[0];
while (true) {
await new Promise(resolve => setTimeout(resolve, UPLOADER_POLLING_RATE_IN_MILLISECONDS)); const state = await this.api.getUploadState(uri);
await new Promise(resolve => setTimeout(resolve, UPLOADER_POLLING_RATE_IN_MILLISECONDS));
const state = await this.api.getUploadState(uri);
if (state && state.resourceUri) {
resource.resourceUri = state.resourceUri;
break;
Expand Down Expand Up @@ -382,6 +383,7 @@ export type FileUploadOptions = Hooks & FileOptions & {
export type FileDownloadOptions = Hooks & {
path?: string,
skipSave?: boolean,
public?: boolean,
}

export type FileGetOptions = FileDownloadOptions & {
Expand Down
2 changes: 1 addition & 1 deletion src/core/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class StackService extends NodeService<Stack> {
if (!service.isPublic) {
await version.decrypt();
const tags = await this.api.getTransactionTags(id);
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase()
const encryptedKey = tags.find(tag => tag.name.toLowerCase() === encryptionTags.ENCRYPTED_KEY.toLowerCase()
|| tag.name.toLowerCase() === encryptionTagsLegacy.ENCRYPTED_KEY.toLowerCase())?.value
const iv = tags.find(tag => tag.name === encryptionTags.IV
|| tag.name.toLowerCase() === encryptionTagsLegacy.IV.toLowerCase())?.value
Expand Down

0 comments on commit a4c8587

Please sign in to comment.