Skip to content
Merged
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
52 changes: 52 additions & 0 deletions components/pixelbin/actions/create-folder/create-folder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import app from "../../pixelbin.app.mjs";

export default {
key: "pixelbin-create-folder",
name: "Create Folder",
description: "Creates a new folder in Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
optional: false,
description: "Name of the folder.",
propDefinition: [
app,
"name",
],
},
path: {
description: "Path of the containing folder. Eg. `folder1/folder2`.",
propDefinition: [
app,
"path",
],
},
},
methods: {
createFolder(args = {}) {
return this.app.post({
path: "/folders",
...args,
});
},
},
async run({ $ }) {
const {
createFolder,
name,
path,
} = this;

const response = await createFolder({
$,
data: {
name,
path,
},
});
$.export("$summary", `Successfully created folder with ID \`${response._id}\`.`);
return response;
},
};
47 changes: 47 additions & 0 deletions components/pixelbin/actions/delete-file/delete-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import app from "../../pixelbin.app.mjs";

export default {
key: "pixelbin-delete-file",
name: "Delete File",
description: "Deletes a file from Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
version: "0.0.1",
type: "action",
props: {
app,
path: {
optional: false,
propDefinition: [
app,
"path",
() => ({
params: {
onlyFolders: false,
onlyFiles: true,
},
}),
],
},
},
methods: {
deleteFile({
path, ...args
}) {
return this.app.delete({
path: `/files/${path}`,
...args,
});
},
},
async run({ $ }) {
const {
deleteFile,
path,
} = this;
const response = await deleteFile({
$,
path,
});
$.export("$summary", `Successfully deleted file with ID \`${response._id}\`.`);
return response;
},
};
65 changes: 65 additions & 0 deletions components/pixelbin/actions/list-files/list-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import app from "../../pixelbin.app.mjs";

export default {
key: "pixelbin-list-files",
name: "List Files",
description: "List all files. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
description: "Find items with matching name.",
propDefinition: [
app,
"name",
],
},
path: {
description: "Find items with matching path.",
propDefinition: [
app,
"path",
],
},
format: {
type: "string",
label: "Format",
description: "Find items with matching format.",
optional: true,
},
tags: {
description: "Find items containing these tags",
propDefinition: [
app,
"tags",
],
},
},
async run({ $ }) {
const {
app,
name,
path,
format,
tags,
} = this;

const result = await app.paginate({
resourcesFn: app.listFiles,
resourcesFnArgs: {
$,
params: {
name,
path,
format,
tags,
onlyFiles: true,
},
},
resourceName: "items",
});
$.export("$summary", `Successfully listed \`${result.length}\` file(s).`);
return result;
},
};
97 changes: 97 additions & 0 deletions components/pixelbin/actions/upload-asset-url/upload-asset-url.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import app from "../../pixelbin.app.mjs";

export default {
key: "pixelbin-upload-asset-url",
name: "Upload Asset From URL",
description: "Uploads an asset to Pixelbin from a given URL. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
version: "0.0.1",
type: "action",
props: {
app,
url: {
type: "string",
label: "URL",
description: "URL of the asset you want to upload.",
},
path: {
propDefinition: [
app,
"path",
],
},
name: {
propDefinition: [
app,
"name",
],
},
access: {
propDefinition: [
app,
"access",
],
},
tags: {
propDefinition: [
app,
"tags",
],
},
metadata: {
propDefinition: [
app,
"metadata",
],
},
overwrite: {
propDefinition: [
app,
"overwrite",
],
},
filenameOverride: {
propDefinition: [
app,
"filenameOverride",
],
},
},
methods: {
uploadAssetFromUrl(args = {}) {
return this.app.post({
path: "/upload/url",
...args,
});
},
},
async run({ $ }) {
const {
uploadAssetFromUrl,
url,
path,
name,
access,
tags,
metadata,
overwrite,
filenameOverride,
} = this;

const response = await uploadAssetFromUrl({
$,
data: {
url,
path,
name,
access,
tags,
metadata,
overwrite,
filenameOverride,
},
});

$.export("$summary", `Successfully uploaded asset with ID: \`${response._id}\`.`);
return response;
},
};
112 changes: 112 additions & 0 deletions components/pixelbin/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import fs from "fs";
import FormData from "form-data";
import { ConfigurationError } from "@pipedream/platform";
import app from "../../pixelbin.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "pixelbin-upload-file",
name: "Upload File",
description: "Upload a file to Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)",
version: "0.0.1",
type: "action",
props: {
app,
filePath: {
type: "string",
label: "File Path",
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).",
},
path: {
propDefinition: [
app,
"path",
],
},
name: {
propDefinition: [
app,
"name",
],
},
access: {
propDefinition: [
app,
"access",
],
},
tags: {
propDefinition: [
app,
"tags",
],
},
metadata: {
propDefinition: [
app,
"metadata",
],
},
overwrite: {
propDefinition: [
app,
"overwrite",
],
},
filenameOverride: {
propDefinition: [
app,
"filenameOverride",
],
},
},
methods: {
uploadFile(args = {}) {
return this.app.post({
path: "/upload/direct",
headers: {
"Content-Type": "multipart/form-data",
},
...args,
});
},
},
async run({ $ }) {
const {
uploadFile,
filePath,
path,
name,
access,
tags,
metadata,
overwrite,
filenameOverride,
} = this;

if (!filePath.startsWith("/tmp/")) {
throw new ConfigurationError("File must be located in `/tmp` directory.");
}

const data = new FormData();
data.append("file", fs.createReadStream(filePath));

utils.appendPropsToFormData(data, {
path,
name,
access,
tags,
metadata,
overwrite,
filenameOverride,
});

const response = await uploadFile({
$,
data,
});

$.export("$summary", `Successfully uploaded file with ID \`${response._id}\`.`);
return response;
},
};
Loading
Loading