guratan 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/cli.d.ts +5 -2
- package/dist/cli.js +5 -2
- package/dist/main.js +26 -3
- package/dist/tsend.d.ts +5 -0
- package/dist/tsend.js +2 -2
- package/dist/tshare.d.ts +8 -0
- package/dist/tshare.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,13 +4,31 @@ Google Drive へファイルを送信する簡易ツール。
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
+
### send
|
|
8
|
+
|
|
7
9
|
```
|
|
8
10
|
$ GOOGLE_APPLICATION_CREDENTIALS=./gha-creds-temp.json npx guratan send --parent-id 12345ABC --dest-file-name test.txt --src-file-name path/to/test.txt
|
|
9
11
|
```
|
|
10
12
|
|
|
11
13
|
- `GOOGLE_APPLICATION_CREDENTIALS` にはサービスアカウントの鍵ファイルを指定
|
|
12
14
|
- 送信先フォルダー(`--parent-id`) に同名ファイル(`--dest-file-name`) が存在するときは上書きされる
|
|
15
|
+
- 同名ファイルが複数ある場合は最初にヒットしたものが上書きされる
|
|
16
|
+
- `--parent-id` `--dest-file-name` の代わりに `--file-id` で上書きファイルを指定できる
|
|
17
|
+
- 各オプションは環境変数での指定も可能(例. `--parent-id` = `GURATAN_PARENT_ID`)
|
|
18
|
+
- `guratan` からは upload と update のみ可能
|
|
19
|
+
|
|
20
|
+
### share
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
$ GOOGLE_APPLICATION_CREDENTIALS=./gha-creds-temp.json npx guratan share --file-id 12345ABC --type anyone --role reader
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `GOOGLE_APPLICATION_CREDENTIALS` にはサービスアカウントの鍵ファイルを指定
|
|
27
|
+
- `--file-id` の permission を作成/上書きすることで共有設定を変更する
|
|
28
|
+
- `--file-id` の代わりに `--parent-id` `--dest-file-name` で変更ファイルを指定できる
|
|
29
|
+
- 同名ファイルが複数ある場合は最初にヒットしたもののみが変更される
|
|
13
30
|
- 各オプションは環境変数での指定も可能(例. `--parent-id` = `GURATAN_PARENT_ID`)
|
|
31
|
+
- `guratan` から permission の削除はできない
|
|
14
32
|
|
|
15
33
|
## License
|
|
16
34
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare type Opts = {
|
|
|
5
5
|
stderr: Writable;
|
|
6
6
|
};
|
|
7
7
|
declare type OptsSend = Opts & {
|
|
8
|
+
fileId: string;
|
|
8
9
|
parentId: string;
|
|
9
10
|
destFileName: string;
|
|
10
11
|
srcFileName: string;
|
|
@@ -14,6 +15,8 @@ declare type OptsSend = Opts & {
|
|
|
14
15
|
};
|
|
15
16
|
declare type OptsShare = Opts & {
|
|
16
17
|
fileId: string;
|
|
18
|
+
parentId: string;
|
|
19
|
+
destFileName: string;
|
|
17
20
|
type: string;
|
|
18
21
|
role: string;
|
|
19
22
|
emailAddress: string;
|
|
@@ -26,6 +29,6 @@ declare type OptsShare = Opts & {
|
|
|
26
29
|
emailMessage: string;
|
|
27
30
|
printId: boolean;
|
|
28
31
|
};
|
|
29
|
-
export declare const cliSend: ({ parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }: OptsSend) => Promise<number>;
|
|
30
|
-
export declare const cliShare: ({ fileId, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }: OptsShare) => Promise<number>;
|
|
32
|
+
export declare const cliSend: ({ fileId, parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }: OptsSend) => Promise<number>;
|
|
33
|
+
export declare const cliShare: ({ fileId, parentId, destFileName, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }: OptsShare) => Promise<number>;
|
|
31
34
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { driveClient } from './tdrive.js';
|
|
2
2
|
import { sendFile } from './tsend.js';
|
|
3
3
|
import { createPermisson } from './tshare.js';
|
|
4
|
-
export const cliSend = async ({ parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }) => {
|
|
4
|
+
export const cliSend = async ({ fileId, parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }) => {
|
|
5
5
|
try {
|
|
6
6
|
const id = await sendFile(driveClient(), {
|
|
7
|
+
fileId,
|
|
7
8
|
parentId,
|
|
8
9
|
destFileName,
|
|
9
10
|
srcFileName,
|
|
@@ -21,10 +22,12 @@ export const cliSend = async ({ parentId, destFileName, srcFileName, destMimeTyp
|
|
|
21
22
|
}
|
|
22
23
|
return 0;
|
|
23
24
|
};
|
|
24
|
-
export const cliShare = async ({ fileId, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }) => {
|
|
25
|
+
export const cliShare = async ({ fileId, parentId, destFileName, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }) => {
|
|
25
26
|
try {
|
|
26
27
|
const id = await createPermisson(driveClient(), {
|
|
27
28
|
fileId,
|
|
29
|
+
parentId,
|
|
30
|
+
destFileName,
|
|
28
31
|
type,
|
|
29
32
|
role,
|
|
30
33
|
emailAddress,
|
package/dist/main.js
CHANGED
|
@@ -8,14 +8,22 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
8
8
|
.env(envVarsPrefix)
|
|
9
9
|
.command('send [OPTIONS]', 'send file to folder in Google Drive', (yargs) => {
|
|
10
10
|
return yargs.options({
|
|
11
|
+
'file-id': {
|
|
12
|
+
type: 'string',
|
|
13
|
+
default: '',
|
|
14
|
+
required: false,
|
|
15
|
+
description: 'The ID of the file or shared drive.'
|
|
16
|
+
},
|
|
11
17
|
'parent-id': {
|
|
12
18
|
type: 'string',
|
|
13
|
-
|
|
19
|
+
default: '',
|
|
20
|
+
required: false,
|
|
14
21
|
description: 'The IDs of the parent folders which contain the file.'
|
|
15
22
|
},
|
|
16
23
|
'dest-file-name': {
|
|
17
24
|
type: 'string',
|
|
18
|
-
|
|
25
|
+
default: '',
|
|
26
|
+
required: false,
|
|
19
27
|
description: 'The name of the file in remote'
|
|
20
28
|
},
|
|
21
29
|
'src-file-name': {
|
|
@@ -47,10 +55,22 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
47
55
|
return yargs.options({
|
|
48
56
|
'file-id': {
|
|
49
57
|
type: 'string',
|
|
50
|
-
default: '
|
|
58
|
+
default: '',
|
|
51
59
|
required: false,
|
|
52
60
|
description: 'The ID of the file or shared drive.'
|
|
53
61
|
},
|
|
62
|
+
'parent-id': {
|
|
63
|
+
type: 'string',
|
|
64
|
+
default: '',
|
|
65
|
+
required: false,
|
|
66
|
+
description: 'The IDs of the parent folders which contain the file.'
|
|
67
|
+
},
|
|
68
|
+
'dest-file-name': {
|
|
69
|
+
type: 'string',
|
|
70
|
+
default: '',
|
|
71
|
+
required: false,
|
|
72
|
+
description: 'The name of the file in remote'
|
|
73
|
+
},
|
|
54
74
|
type: {
|
|
55
75
|
choices: ['user', 'group', 'domain', 'anyone'],
|
|
56
76
|
required: false,
|
|
@@ -121,6 +141,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
121
141
|
switch (`${argv._[0]}`) {
|
|
122
142
|
case 'send':
|
|
123
143
|
process.exit(await cliSend({
|
|
144
|
+
fileId: argv['file-id'],
|
|
124
145
|
parentId: argv['parent-id'] || '',
|
|
125
146
|
destFileName: argv['dest-file-name'] || '',
|
|
126
147
|
srcFileName: argv['src-file-name'] || '',
|
|
@@ -134,6 +155,8 @@ switch (`${argv._[0]}`) {
|
|
|
134
155
|
case 'share':
|
|
135
156
|
process.exit(await cliShare({
|
|
136
157
|
fileId: argv['file-id'],
|
|
158
|
+
parentId: argv['parent-id'] || '',
|
|
159
|
+
destFileName: argv['dest-file-name'] || '',
|
|
137
160
|
type: argv['type'],
|
|
138
161
|
role: argv['role'],
|
|
139
162
|
emailAddress: argv['email-address'],
|
package/dist/tsend.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export declare class UpdateFileError extends Error {
|
|
|
12
12
|
* Options for sendFile().
|
|
13
13
|
*/
|
|
14
14
|
export declare type SendFileOpts = {
|
|
15
|
+
/**
|
|
16
|
+
* @type The ID of the file or shared drive.
|
|
17
|
+
*/
|
|
18
|
+
fileId: string;
|
|
19
|
+
/**
|
|
15
20
|
/**
|
|
16
21
|
* @type The IDs of the parent folders which contain the file.
|
|
17
22
|
*/
|
package/dist/tsend.js
CHANGED
|
@@ -123,8 +123,8 @@ export async function updateFile(drive, opts) {
|
|
|
123
123
|
* @returns id of file in Google Drive
|
|
124
124
|
*/
|
|
125
125
|
export async function sendFile(drive, opts) {
|
|
126
|
-
const { parentId, destFileName, srcFileName, destMimeType, srcMimeType } = opts;
|
|
127
|
-
|
|
126
|
+
const { fileId: inFileId, parentId, destFileName, srcFileName, destMimeType, srcMimeType } = opts;
|
|
127
|
+
let fileId = inFileId !== '' ? inFileId : await getFileId(drive, parentId, destFileName);
|
|
128
128
|
if (fileId === '') {
|
|
129
129
|
return uploadFile(drive, {
|
|
130
130
|
parentId,
|
package/dist/tshare.d.ts
CHANGED
|
@@ -13,6 +13,14 @@ export declare type CreatePermissonOpts = {
|
|
|
13
13
|
* @type The ID of the file or shared drive.
|
|
14
14
|
*/
|
|
15
15
|
fileId: string;
|
|
16
|
+
/**
|
|
17
|
+
* @type The IDs of the parent folders which contain the file.
|
|
18
|
+
*/
|
|
19
|
+
parentId: string;
|
|
20
|
+
/**
|
|
21
|
+
* @type The name of the file in remote
|
|
22
|
+
*/
|
|
23
|
+
destFileName: string;
|
|
16
24
|
/**
|
|
17
25
|
* @type The type of the grantee.
|
|
18
26
|
*/
|
package/dist/tshare.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getFileId } from './tsend.js';
|
|
1
2
|
export class CreatePermissonError extends Error {
|
|
2
3
|
constructor(message) {
|
|
3
4
|
//https://stackoverflow.com/questions/41102060/typescript-extending-error-class
|
|
@@ -21,7 +22,8 @@ export class UpdatePermissonError extends Error {
|
|
|
21
22
|
export async function createPermisson(drive, opts) {
|
|
22
23
|
let created = false;
|
|
23
24
|
try {
|
|
24
|
-
const { fileId, type, role, emailAddress, domain, view, allowFileDiscovery, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage } = opts;
|
|
25
|
+
const { fileId: inFileId, parentId, destFileName, type, role, emailAddress, domain, view, allowFileDiscovery, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage } = opts;
|
|
26
|
+
const fileId = inFileId || (await getFileId(drive, parentId, destFileName));
|
|
25
27
|
const createParams = {
|
|
26
28
|
requestBody: {
|
|
27
29
|
type,
|