Skip to content

Commit dd8a023

Browse files
authored
PixelBin: New action components (#14146)
1 parent 511331a commit dd8a023

File tree

10 files changed

+631
-7
lines changed

10 files changed

+631
-7
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import app from "../../pixelbin.app.mjs";
2+
3+
export default {
4+
key: "pixelbin-create-folder",
5+
name: "Create Folder",
6+
description: "Creates a new folder in Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
optional: false,
13+
description: "Name of the folder.",
14+
propDefinition: [
15+
app,
16+
"name",
17+
],
18+
},
19+
path: {
20+
description: "Path of the containing folder. Eg. `folder1/folder2`.",
21+
propDefinition: [
22+
app,
23+
"path",
24+
],
25+
},
26+
},
27+
methods: {
28+
createFolder(args = {}) {
29+
return this.app.post({
30+
path: "/folders",
31+
...args,
32+
});
33+
},
34+
},
35+
async run({ $ }) {
36+
const {
37+
createFolder,
38+
name,
39+
path,
40+
} = this;
41+
42+
const response = await createFolder({
43+
$,
44+
data: {
45+
name,
46+
path,
47+
},
48+
});
49+
$.export("$summary", `Successfully created folder with ID \`${response._id}\`.`);
50+
return response;
51+
},
52+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import app from "../../pixelbin.app.mjs";
2+
3+
export default {
4+
key: "pixelbin-delete-file",
5+
name: "Delete File",
6+
description: "Deletes a file from Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
path: {
12+
optional: false,
13+
propDefinition: [
14+
app,
15+
"path",
16+
() => ({
17+
params: {
18+
onlyFolders: false,
19+
onlyFiles: true,
20+
},
21+
}),
22+
],
23+
},
24+
},
25+
methods: {
26+
deleteFile({
27+
path, ...args
28+
}) {
29+
return this.app.delete({
30+
path: `/files/${path}`,
31+
...args,
32+
});
33+
},
34+
},
35+
async run({ $ }) {
36+
const {
37+
deleteFile,
38+
path,
39+
} = this;
40+
const response = await deleteFile({
41+
$,
42+
path,
43+
});
44+
$.export("$summary", `Successfully deleted file with ID \`${response._id}\`.`);
45+
return response;
46+
},
47+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import app from "../../pixelbin.app.mjs";
2+
3+
export default {
4+
key: "pixelbin-list-files",
5+
name: "List Files",
6+
description: "List all files. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
description: "Find items with matching name.",
13+
propDefinition: [
14+
app,
15+
"name",
16+
],
17+
},
18+
path: {
19+
description: "Find items with matching path.",
20+
propDefinition: [
21+
app,
22+
"path",
23+
],
24+
},
25+
format: {
26+
type: "string",
27+
label: "Format",
28+
description: "Find items with matching format.",
29+
optional: true,
30+
},
31+
tags: {
32+
description: "Find items containing these tags",
33+
propDefinition: [
34+
app,
35+
"tags",
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
const {
41+
app,
42+
name,
43+
path,
44+
format,
45+
tags,
46+
} = this;
47+
48+
const result = await app.paginate({
49+
resourcesFn: app.listFiles,
50+
resourcesFnArgs: {
51+
$,
52+
params: {
53+
name,
54+
path,
55+
format,
56+
tags,
57+
onlyFiles: true,
58+
},
59+
},
60+
resourceName: "items",
61+
});
62+
$.export("$summary", `Successfully listed \`${result.length}\` file(s).`);
63+
return result;
64+
},
65+
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import app from "../../pixelbin.app.mjs";
2+
3+
export default {
4+
key: "pixelbin-upload-asset-url",
5+
name: "Upload Asset From URL",
6+
description: "Uploads an asset to Pixelbin from a given URL. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
url: {
12+
type: "string",
13+
label: "URL",
14+
description: "URL of the asset you want to upload.",
15+
},
16+
path: {
17+
propDefinition: [
18+
app,
19+
"path",
20+
],
21+
},
22+
name: {
23+
propDefinition: [
24+
app,
25+
"name",
26+
],
27+
},
28+
access: {
29+
propDefinition: [
30+
app,
31+
"access",
32+
],
33+
},
34+
tags: {
35+
propDefinition: [
36+
app,
37+
"tags",
38+
],
39+
},
40+
metadata: {
41+
propDefinition: [
42+
app,
43+
"metadata",
44+
],
45+
},
46+
overwrite: {
47+
propDefinition: [
48+
app,
49+
"overwrite",
50+
],
51+
},
52+
filenameOverride: {
53+
propDefinition: [
54+
app,
55+
"filenameOverride",
56+
],
57+
},
58+
},
59+
methods: {
60+
uploadAssetFromUrl(args = {}) {
61+
return this.app.post({
62+
path: "/upload/url",
63+
...args,
64+
});
65+
},
66+
},
67+
async run({ $ }) {
68+
const {
69+
uploadAssetFromUrl,
70+
url,
71+
path,
72+
name,
73+
access,
74+
tags,
75+
metadata,
76+
overwrite,
77+
filenameOverride,
78+
} = this;
79+
80+
const response = await uploadAssetFromUrl({
81+
$,
82+
data: {
83+
url,
84+
path,
85+
name,
86+
access,
87+
tags,
88+
metadata,
89+
overwrite,
90+
filenameOverride,
91+
},
92+
});
93+
94+
$.export("$summary", `Successfully uploaded asset with ID: \`${response._id}\`.`);
95+
return response;
96+
},
97+
};
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import fs from "fs";
2+
import FormData from "form-data";
3+
import { ConfigurationError } from "@pipedream/platform";
4+
import app from "../../pixelbin.app.mjs";
5+
import utils from "../../common/utils.mjs";
6+
7+
export default {
8+
key: "pixelbin-upload-file",
9+
name: "Upload File",
10+
description: "Upload a file to Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
app,
15+
filePath: {
16+
type: "string",
17+
label: "File Path",
18+
description: "Assete file path. The path to the file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
19+
},
20+
path: {
21+
propDefinition: [
22+
app,
23+
"path",
24+
],
25+
},
26+
name: {
27+
propDefinition: [
28+
app,
29+
"name",
30+
],
31+
},
32+
access: {
33+
propDefinition: [
34+
app,
35+
"access",
36+
],
37+
},
38+
tags: {
39+
propDefinition: [
40+
app,
41+
"tags",
42+
],
43+
},
44+
metadata: {
45+
propDefinition: [
46+
app,
47+
"metadata",
48+
],
49+
},
50+
overwrite: {
51+
propDefinition: [
52+
app,
53+
"overwrite",
54+
],
55+
},
56+
filenameOverride: {
57+
propDefinition: [
58+
app,
59+
"filenameOverride",
60+
],
61+
},
62+
},
63+
methods: {
64+
uploadFile(args = {}) {
65+
return this.app.post({
66+
path: "/upload/direct",
67+
headers: {
68+
"Content-Type": "multipart/form-data",
69+
},
70+
...args,
71+
});
72+
},
73+
},
74+
async run({ $ }) {
75+
const {
76+
uploadFile,
77+
filePath,
78+
path,
79+
name,
80+
access,
81+
tags,
82+
metadata,
83+
overwrite,
84+
filenameOverride,
85+
} = this;
86+
87+
if (!filePath.startsWith("/tmp/")) {
88+
throw new ConfigurationError("File must be located in `/tmp` directory.");
89+
}
90+
91+
const data = new FormData();
92+
data.append("file", fs.createReadStream(filePath));
93+
94+
utils.appendPropsToFormData(data, {
95+
path,
96+
name,
97+
access,
98+
tags,
99+
metadata,
100+
overwrite,
101+
filenameOverride,
102+
});
103+
104+
const response = await uploadFile({
105+
$,
106+
data,
107+
});
108+
109+
$.export("$summary", `Successfully uploaded file with ID \`${response._id}\`.`);
110+
return response;
111+
},
112+
};

0 commit comments

Comments
 (0)