-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
281b257
commit d07abf9
Showing
21 changed files
with
747 additions
and
84 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace ckan { | ||
export namespace CKANEXT_FILES { | ||
export namespace adapters { | ||
export type S3UploadInfo = UploadInfo & { | ||
storage_data: StorageData & { upload_url: string }; | ||
}; | ||
|
||
export class S3Multipart extends Multipart { | ||
async __x_uploadChunk( | ||
info: S3UploadInfo, | ||
part: Blob, | ||
start: number, | ||
): Promise<UploadInfo> { | ||
if (!part.size) { | ||
throw new Error("0-length chunks are not allowed"); | ||
} | ||
|
||
debugger; | ||
|
||
const request = new XMLHttpRequest(); | ||
|
||
request.open("PUT", info.storage_data.upload_url); | ||
request.send(part); | ||
|
||
const resp: any = await new Promise((done, fail) => { | ||
request.addEventListener("load", (event) => done(request)); | ||
}); | ||
let uploaded; | ||
|
||
if ([200, 201].includes(resp.status)) { | ||
uploaded = info.size; | ||
} else { | ||
throw new Error(await resp.responseText); | ||
} | ||
|
||
if (!Number.isInteger(uploaded)) { | ||
throw new Error(`Invalid uploaded size ${uploaded}`); | ||
} | ||
|
||
return new Promise((done, fail) => { | ||
this.sandbox.client.call( | ||
"POST", | ||
"files_multipart_update", | ||
{ | ||
id: info.id, | ||
uploaded, | ||
etag: resp.getResponseHeader("ETag") | ||
}, | ||
(data: any) => { | ||
done(data.result); | ||
}, | ||
(resp: any) => { | ||
fail( | ||
typeof resp.responseJSON === "string" | ||
? resp.responseText | ||
: resp.responseJSON.error, | ||
); | ||
}, | ||
); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.