Skip to content

Commit ae80842

Browse files
allow format selection
1 parent 91ba94b commit ae80842

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

components/google_drive/actions/create-file-from-text/create-file-from-text.mjs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "google_drive-create-file-from-text",
66
name: "Create New File From Text",
77
description: "Create a new file from plain text. [See the documentation](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
8-
version: "0.1.7",
8+
version: "0.2.0",
99
type: "action",
1010
props: {
1111
googleDrive,
@@ -44,24 +44,66 @@ export default {
4444
optional: true,
4545
default: "",
4646
},
47+
mimeType: {
48+
type: "string",
49+
label: "Conversion Format",
50+
description:
51+
"The [format](https://developers.google.com/drive/api/v3/ref-export-formats) in which the text is presented",
52+
optional: true,
53+
default: "text/plain",
54+
options: [
55+
{
56+
value: "text/plain",
57+
label: "Plain text",
58+
},
59+
{
60+
value: "text/markdown",
61+
label: "Markdown",
62+
},
63+
{
64+
value: "text/html",
65+
label: "HTML",
66+
},
67+
{
68+
value: "application/rtf",
69+
label: "Rich Text",
70+
},
71+
{
72+
value: "text/csv",
73+
label: "CSV",
74+
},
75+
],
76+
},
4777
},
4878
async run({ $ }) {
4979
const {
5080
parentId,
5181
name,
5282
content,
83+
mimeType,
5384
} = this;
5485
const file = Readable.from([
5586
content,
5687
]);
88+
const drive = this.googleDrive.drive();
5789
const driveId = this.googleDrive.getDriveId(this.drive);
58-
const resp = await this.googleDrive.createFile({
59-
mimeType: "text/plain",
60-
file,
61-
name,
62-
parentId,
63-
driveId,
90+
const parent = parentId ?? driveId;
91+
92+
const { data: resp } = await drive.files.create({
93+
supportsAllDrives: true,
94+
media: {
95+
mimeType,
96+
body: file,
97+
},
98+
requestBody: {
99+
name,
100+
mimeType: "application/vnd.google-apps.document",
101+
parents: [
102+
parent,
103+
],
104+
},
64105
});
106+
65107
$.export("$summary", `Successfully created a new file, "${resp.name}"`);
66108
return resp;
67109
},

0 commit comments

Comments
 (0)