Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding blueprint device params to upload files [SDK-JS-43] #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/modules/Resources/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ class Files extends TagoIOModule<GenericModuleParams> {
private async createMultipartUpload(filename: string, options?: UploadOptions) {
const { dashboard, widget, fieldId, isPublic, contentType } = options || {};

const path = dashboard && widget && fieldId ? `/data/files/${dashboard}/${widget}` : `/files`;
const path = dashboard && widget ? `/data/files/${dashboard}/${widget}` : `/files`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image Marker does not have a field id and stills uses /data/files/... path.


const result = await this.doRequest<any>({
path,
method: "POST",
params: {
...(options?.blueprint_devices?.length > 0 && { blueprint_devices: options.blueprint_devices }),
},
body: {
multipart_action: "start",
filename,
Expand Down Expand Up @@ -258,6 +261,9 @@ class Files extends TagoIOModule<GenericModuleParams> {
const result = await this.doRequest<{ ETag: string }>({
path,
method: "POST",
params: {
...(options?.blueprint_devices?.length > 0 && { blueprint_devices: options.blueprint_devices }),
},
body: form,
maxContentLength: Infinity,
headers,
Expand Down Expand Up @@ -334,6 +340,9 @@ class Files extends TagoIOModule<GenericModuleParams> {
const result = await this.doRequest<{ file: string }>({
path,
method: "POST",
params: {
...(options?.blueprint_devices?.length > 0 && { blueprint_devices: options.blueprint_devices }),
},
body: {
multipart_action: "end",
upload_id: uploadID,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/Resources/files.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GenericID } from "../../types";

interface FileQuery {
path?: string;
paginationToken?: string;
Expand Down Expand Up @@ -91,6 +93,10 @@ type UploadOptions = {
* will provide the upload percentage for this file
*/
onProgress?: (percentage: number) => any;
/**
* map blueprint devices to real devices, so BP Device ID path is replaced by the real device ID
*/
blueprint_devices?: { origin: GenericID; id: GenericID; bucket?: GenericID }[];
};

export { FileQuery, FileListInfo, Base64File, MoveFiles, FilesPermission, UploadOptions, CopyFiles };
Loading