pcs-cli 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sobird
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # pcs CLI
2
+
3
+ 百度个人云存储命令行接口
4
+
5
+ [![npm][npm]][npm-url]
6
+ [![Build Status][build-status]][build-status-url]
7
+ [![Install Size][size]][size-url]
8
+
9
+ ## 安装
10
+
11
+ ```sh
12
+ npm i -g pcs-cli
13
+ ```
14
+
15
+ ## 使用
16
+ 在终端执行下面命令:
17
+
18
+ ```
19
+ pcs-cli [command] [options]
20
+ ```
21
+
22
+ ### 可用命令
23
+ ```
24
+ Commands:
25
+ init [options] initialize baidu pcs
26
+ refresh [options] refresh token
27
+ quota [options] check your cloud storage status
28
+ meta [options] [path] get path meta
29
+ list|ll [options] [path] list directory contents
30
+ upload [options] [pattern] [remote] upload local file
31
+ download|dl [options] [remote] [local] download remote file
32
+ delete|rm [options] <remote> delete remote file
33
+ fetch [options] [source] [remote] fetch source to remote
34
+ help [command] display help for command
35
+ ```
36
+
37
+ ### init
38
+ 在初始化之前,需要提供百度PCS应用的name,key,secret。如果没有请访问 [创建应用](https://pan.baidu.com/union/console/createapp) 进行创建,如果已有应用请访问 [应用列表](https://pan.baidu.com/union/console/applist) 查看应用信息。
39
+
40
+ ```sh
41
+ pcs init -n name -k key -s secret
42
+ # 或者 根据提示填写应用的name key secret
43
+ pcs init
44
+ # 如果本地已存在有效的access_token 再次运行该命令将会有如下提示
45
+ Your access token has not expired (expiration date: 2023-12-10 22:49:14).
46
+ ? Do you want to continue initializing? › (y/N)
47
+ # 选择yes将会重新生成token,否则取消操作
48
+ ```
49
+ 初始化完成后,将在本地生成一个有效期30天的token,存放路径为`~/.pcs-cli`。
50
+
51
+ ### refresh
52
+ `access_token` 有效期30天,过期后支持刷新,刷新后的 `access_token` 有效期仍为 30 天,刷新 `access_token` 请按需刷新,不需要不停的刷新。
53
+
54
+ 刷新请求,如果API返回失败,旧的 `refresh_token` 会失效,此时需要重新发起授权请求,获取新的 `access_token`、`refresh_token`,而不是使用旧的 `refresh_token` 循环再发起刷新请求。
55
+
56
+ `refresh_token` 只支持使用一次,`refresh_token` 使用后失效,下次刷新 `access_token` 时需要使用上一次刷新请求响应中的 `refresh_token`。
57
+
58
+ ```sh
59
+ pcs refresh
60
+ Successfully refreshed token
61
+ ```
62
+
63
+ ### quota
64
+ 该命令用来查看pcs配额状态
65
+
66
+ ```sh
67
+ pcs quota
68
+ ███████████████░░░░░░░░░░░░░░░ 1.6TB/3.1TB 51%
69
+ ```
70
+
71
+ ### meta
72
+ 用于获取用户指定文件的meta信息,meta信息包括文件名字、文件创建时间、文件的下载地址等。
73
+
74
+ ```sh
75
+ # 不指定路径,默认使用应用的根路径
76
+ pcs meta
77
+ {
78
+ app_id: 123456,
79
+ category: 6,
80
+ ctime: 1699853947,
81
+ extent_int3: 2919719500,
82
+ extent_tinyint1: 0,
83
+ extent_tinyint2: 0,
84
+ extent_tinyint3: 0,
85
+ extent_tinyint4: 0,
86
+ from_type: 0,
87
+ fs_id: 680163361072043,
88
+ ifhassubdir: 0,
89
+ isdelete: 0,
90
+ isdir: 1,
91
+ local_ctime: 1699853947,
92
+ local_mtime: 1699853947,
93
+ mtime: 1699873611,
94
+ oper_id: 2919719500,
95
+ owner_id: 0,
96
+ owner_type: 0,
97
+ parent_path: '/apps',
98
+ path: '/apps/appName',
99
+ privacy: 2,
100
+ real_category: '',
101
+ server_ctime: 1699853947,
102
+ server_filename: 'appName',
103
+ server_mtime: 1699873611,
104
+ share: 0,
105
+ size: 0,
106
+ status: 0,
107
+ tkbind_id: 0,
108
+ user_id: 12345678,
109
+ videotag: 0,
110
+ wpfile: 0
111
+ }
112
+ ```
113
+
114
+ ### list
115
+ 获取指定目录下的文件列表。
116
+
117
+ ```sh
118
+ # 不指定路径,默认使用应用的根路径
119
+ pcs list
120
+ 2023/11/13 13:40:12 1MB split23.mp4
121
+ 2023/11/13 13:40:14 1MB split22.mp4
122
+ 2023/11/13 13:40:15 107B package.json
123
+ 2023/11/13 13:40:17 527.7KB IMG_3224.jpeg
124
+ 2023/11/13 13:40:23 2.21MB IMG_3222.jpeg
125
+ ```
126
+
127
+ ### upload
128
+ 上传文件
129
+
130
+ ```sh
131
+ # 不指定本地文件路径,默认上传当前目录下的所有文件
132
+ pcs upload
133
+ ```
134
+
135
+ ### download
136
+ 下载文件
137
+
138
+ ```sh
139
+ # 不指定远程文件路径,默认下载远程根目录下的所有文件
140
+ pcs download
141
+ ```
142
+
143
+ ### delete
144
+ 删除远程文件
145
+
146
+ ```sh
147
+ pcs rm
148
+ ```
149
+
150
+ ### fetch
151
+ 离线下载(貌似不支持)
152
+
153
+ ```sh
154
+ pcs fetch [source] [remote]
155
+ ```
156
+
157
+ [npm]: https://img.shields.io/npm/v/pcs-cli.svg
158
+ [npm-url]: https://www.npmjs.com/package/pcs-cli
159
+ [build-status]: https://img.shields.io/github/actions/workflow/status/sobird/pcs-cli/release-please.yml?label=CI&logo=github
160
+ [build-status-url]: https://github.com/sobird/pcs-cli/actions
161
+ [size]: https://packagephobia.com/badge?p=pcs-cli
162
+ [size-url]: https://packagephobia.com/result?p=pcs-cli
@@ -0,0 +1 @@
1
+ function n(n,t,e,r){return new(e||(e=Promise))((function(o,c){function u(n){try{i(r.next(n))}catch(n){c(n)}}function f(n){try{i(r.throw(n))}catch(n){c(n)}}function i(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,f)}i((r=r.apply(n,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;export{n as _};
package/bin/pcs.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{Command as o}from"commander";import t from"chalk";import{n as r,C as m,A as i,v as e,f as s,l as a}from"../index-7szJY7Td.js";import p from"../command/init.js";import n from"../command/upload.js";import c from"../command/refresh.js";import d from"../command/quota.js";import f from"../command/meta.js";import l from"../command/list.js";import u from"../command/download.js";import j from"../command/delete.js";import k from"../command/fetch.js";import"../_tslib-NbJOzQvB.js";import"fs";import"os";import"path";import"crypto";import"prompts";import"dayjs";import"open";import"../services/pcs.js";import"https";import"progress";import"../utils/axios.js";import"axios";import"glob";import"bytes";import"cliui";const y=new o;y.name(r).description(`Baidu Personal Cloud Storage Scaffold.\n\nYou can get app key by visit ${t.blue.underline(m)}.\nIf you have already created an app, you can visit ${t.blue.underline(i)} and get it in your app's info.`).version(e),y.hook("preAction",((o,r)=>{const m=r.options.find((o=>"--token"===o.long));if(m){const o=s("TOKEN");if(!o||!o.access_token)return void a("Your access token does not exist or has expired",t.red);r.setOptionValue("token",m.defaultValue||o.access_token),["key","secret","refresh_token"].map((t=>o[t]&&r.setOptionValue(t,o[t])))}})),p(y),c(y),d(y),f(y),l(y),n(y),u(y),j(y),k(y),y.parse();
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import t from"chalk";import e from"prompts";import{t as r,l as i}from"../index-7szJY7Td.js";import s from"../services/pcs.js";import"fs";import"os";import"path";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var m=m=>{m.command("delete").alias("rm").description("delete remote file").argument("<remote>","remote path").option("-t --token [token]","access token").action(((m,a)=>o(void 0,void 0,void 0,(function*(){const o=r(m);if(o===r("/")){i("You are about to delete the root directory of the application, which will lose all data",t.red);const{confirm:o}=yield e({type:"confirm",name:"confirm",message:"Are you sure you want to continue?",initial:!1});if(!o)return}try{yield s.delete(a.token,o)}catch(o){const{response:{data:e}}=o;i(`error code ${e.error_code} : ${e.error_msg}`,t.red)}}))))};export{m as default};
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import{sep as t,join as r}from"path";import e from"chalk";import{t as s,a as i,l as a}from"../index-7szJY7Td.js";import n from"../services/pcs.js";import"fs";import"os";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var d=d=>{d.command("download").alias("dl").description("download remote file").argument("[remote]","remote path",t).argument("[local]","local path",".").option("-t --token [token]","access token").action(((t,d,m)=>o(void 0,void 0,void 0,(function*(){const p=s(t);try{const{list:t}=yield n.listFile(m.token,p);0===t.length&&t.push({server_filename:p,path:p,isdir:0}),t.reduce(((t,s)=>o(void 0,void 0,void 0,(function*(){yield t;const o=r(d,i(s.path));return 1===s.isdir?Promise.resolve():(a(`${e.blueBright("==>")} Downloading ${e.green(o)}`),n.download(m.token,s.path,o))}))),Promise.resolve())}catch(o){const{response:{data:t}}=o;a(`error code ${t.error_code||t.statusCode} : ${t.error_msg||t.statusMessage}`,e.red)}}))))};export{d as default};
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import{sep as t}from"path";import r from"chalk";import{t as e,l as s}from"../index-7szJY7Td.js";import i from"../services/pcs.js";import"fs";import"os";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var m=m=>{m.command("fetch").description("fetch source to remote").argument("[source]","source path",t).argument("[remote]","remote path",".").option("-t --token [token]","access token").action(((t,m,p)=>o(void 0,void 0,void 0,(function*(){const o=e(m);try{yield i.fetch(p.token,t,o)}catch(o){const{response:{data:t}}=o;s(`error code ${t.error_code} : ${t.error_msg}`,r.red)}}))))};export{m as default};
@@ -0,0 +1 @@
1
+ import{_ as e}from"../_tslib-NbJOzQvB.js";import{existsSync as t}from"fs";import i from"chalk";import o from"prompts";import s from"dayjs";import n from"open";import{f as r,l as a,J as c,E as p}from"../index-7szJY7Td.js";import d from"../services/pcs.js";import"os";import"path";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var l=l=>{l.command("init").description("initialize baidu pcs").option("-n, --name <string>","app name").option("-k, --key <string>","app key").option("-s, --secret <string>","app secret").action((l=>e(void 0,void 0,void 0,(function*(){const m=r("TOKEN");if(m&&m.access_token){a(`Your access token has not expired (expiration date: ${s(m.expires_time).format("YYYY-MM-DD HH:mm:ss")}).`);const{value:e}=yield o({type:"confirm",name:"value",message:"Do you want to continue initializing?",initial:!1});if(!e)return}const y=r("DEVICE");if(y)return void(yield u(y));const f=[];["name","key","secret"].forEach((e=>{l[e]||f.push({type:"text",name:e,message:`Please enter baidu app ${e}`})}));const h=yield o(f),k=Object.assign(Object.assign({},l),h);if(!["name","key"].every((e=>k[e])))return;let g=!0;if(t(c.APP)){const{value:e}=yield o({type:"confirm",name:"value",message:"Baidu pcs initialization will be begin. If you have already configured before, your old settings will be overwritten. Can you confirm?",initial:!1});g=e}g&&(r("APP",k),yield function(){return e(this,void 0,void 0,(function*(){const e=r("APP"),{key:t="client_id",secret:s}=e;if(s)try{const e=yield d.oauthDevice(t),i=Object.assign(Object.assign({},e),{key:t,secret:s});r("DEVICE",i),yield u(i)}catch(e){const{response:{data:t}}=e;console.log(`OAuth error ${t.error} : ${t.error_description}`)}else{const e=`https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=${t}&redirect_uri=oob&scope=netdisk`;yield n(e);const c=Date.now();a("You'll have to grab the access_token generated by Baidu.",i.hex("#FFA500")),a(""),a(`1. Visit ${i.blue.underline(e)}`),a("2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor"),a('3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes).'),a("4. Copy it and paste here, then press Enter.");const{access_token:d}=yield o({type:"text",name:"access_token",message:"access_token"});if(d){const e=(Date.now()-c)/1e3;r("TOKEN",{access_token:d,expires_in:p-e,key:t,secret:s})}}}))}())}))))};function u(t){return e(this,void 0,void 0,(function*(){const{verification_url:e,user_code:s,device_code:c,key:p,secret:l}=t;yield n(`${e}?code=${s}`),a("Launch your favorite web browser and visit: "),a(e,i.blue.underline),a(`Input ${i.bold.red(s)} as the user code if asked.`),a("After granting access to the application, come back here and ");const{confirm:u}=yield o({type:"confirm",name:"confirm",message:"Press Enter to continue",initial:!0});if(u){const e=yield d.oauthToken(p,l,c);r("TOKEN",Object.assign(Object.assign({},e),{key:p,secret:l})),a("Successfully initialized",i.green),a(`access_token: ${i.yellowBright(e.access_token)}`),a(`refresh_token: ${i.yellowBright(e.refresh_token)}`)}}))}export{l as default};
@@ -0,0 +1 @@
1
+ import{_ as t}from"../_tslib-NbJOzQvB.js";import{sep as o}from"path";import r from"chalk";import i from"dayjs";import s from"bytes";import e from"cliui";import{t as m,l as a}from"../index-7szJY7Td.js";import p from"../services/pcs.js";import"fs";import"os";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var n=n=>{n.command("list").description("list directory contents").argument("[path]","path",o).alias("ll").option("-t --token [token]","access token").action(((o,n)=>t(void 0,void 0,void 0,(function*(){try{const t=e({}),{list:a}=yield p.listFile(n.token,m(o));a.map((o=>{const{server_mtime:e,size:m,server_filename:a,isdir:p}=o,n=1===p?r.blueBright(a):a;return t.div({text:r.gray(i.unix(e).format("YYYY/MM/DD HH:mm:ss")),width:22,padding:[0,0,0,0]},{text:s(m),width:15,align:"right",padding:[0,2,0,0]},{text:n,padding:[0,0,0,0]}),o})),console.log(t.toString())}catch(t){const{response:{data:o}}=t;a(`error code ${o.error_code} : ${o.error_msg}`,r.red)}}))))};export{n as default};
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import{sep as t}from"path";import r from"chalk";import{t as s,l as e}from"../index-7szJY7Td.js";import i from"../services/pcs.js";import"fs";import"os";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var a=a=>{a.command("meta").description("get path meta").argument("[path]","meta path",t).option("-t --token [token]","access token").action(((t,a)=>o(void 0,void 0,void 0,(function*(){try{const{list:o}=yield i.getMeta(a.token,s(t));console.log(o[0])}catch(o){const{response:{data:t}}=o;e(`error code ${t.error_code} : ${t.error_msg}`,r.red)}}))))};export{a as default};
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import t from"progress";import r from"chalk";import e from"bytes";import{l as s}from"../index-7szJY7Td.js";import i from"../services/pcs.js";import"fs";import"os";import"path";import"crypto";import"https";import"../utils/axios.js";import"axios";var p=p=>{p.command("quota").description("check your pcs status").option("-t --token [token]","access token").action((p=>o(void 0,void 0,void 0,(function*(){try{const{quota:o,used:m}=yield i.quotaInfo(p.token);new t(":bar :used/:quota :percent",{complete:"█",incomplete:r.green("░"),width:30,total:o}).tick(m,{used:e(m),quota:e(o)}),s("")}catch(o){const{response:{data:t}}=o;s(`error code ${t.error_code} : ${t.error_msg}`,r.red)}}))))};export{p as default};
@@ -0,0 +1 @@
1
+ import{_ as r}from"../_tslib-NbJOzQvB.js";import e from"chalk";import{f as o,l as t}from"../index-7szJY7Td.js";import s from"../services/pcs.js";import"fs";import"os";import"path";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var i=i=>{i.command("refresh").description("refresh token").option("-t --token [token]","access token").action((i=>r(void 0,void 0,void 0,(function*(){try{const r=yield s.refreshToken(i.key,i.secret,i.refresh_token);o("TOKEN",Object.assign(Object.assign({},r),{key:i.key,secret:i.secret})),t("Successfully refreshed token",e.green)}catch(r){const{response:{data:o}}=r;t(`OAuth error ${o.error} : ${o.error_description}`,e.red)}}))))};export{i as default};
@@ -0,0 +1 @@
1
+ import{_ as o}from"../_tslib-NbJOzQvB.js";import t from"os";import{statSync as r}from"fs";import{sep as e,join as i}from"path";import{glob as s}from"glob";import p from"chalk";import{s as n,t as a,l as m}from"../index-7szJY7Td.js";import l from"../services/pcs.js";import"crypto";import"https";import"progress";import"../utils/axios.js";import"axios";var c=c=>{c.command("upload").description("upload local file").argument("[pattern]","glob pattern","*").argument("[remote]","remote path",e).option("-t --token [token]","access token").option("-b --bytes [size]","Split upload bytes size").option("--thread","Thread").action(((e,c,d)=>o(void 0,void 0,void 0,(function*(){const u=yield s(e,{nodir:!0}),f=!0===d.bytes?1073741824:parseInt(d.bytes,10),b=i(t.tmpdir(),"pcs-cli");try{u.reduce(((t,e)=>o(void 0,void 0,void 0,(function*(){yield t;const o=r(e);if(Number.isInteger(f)&&o.size>f){const o=yield n(e,f,b),t=[];for(const r of o){const{md5:o}=yield l.upload2(d.token,r,"","overwrite","tmpfile");t.push(o)}const r={block_list:t};return l.createSuperFile(d.token,a(i(c,e)),r)}return m(`${p.blueBright("==>")} Uploading ${e}`),l.upload2(d.token,e,a(i(c,e)))}))),Promise.resolve())}catch(o){const{response:{data:t}}=o;console.log(`error code ${t.error_code} : ${t.error_msg}`)}}))))};export{c as default};
@@ -0,0 +1 @@
1
+ import{_ as n}from"./_tslib-NbJOzQvB.js";import{createReadStream as t,readFileSync as o,mkdir as i,writeFile as r,mkdirSync as e,writeFileSync as s,existsSync as c,readFile as u,statSync as a,stat as f}from"fs";import p from"os";import{resolve as d,dirname as m,join as l,basename as h}from"path";import{createHash as v}from"crypto";import g from"chalk";var P="pcs-cli",w="1.1.0";const b=d(p.homedir(),`.${P}`),x={APP:d(b,"pcsapp"),DEVICE:d(b,"device"),TOKEN:d(b,"token")},y=2592e3,O="https://pan.baidu.com/union/console/createapp",A="https://pan.baidu.com/union/console/applist";function E(n,o){const i=v("md5"),r=t(n);r.on("data",(n=>{i.update(n)})),r.on("end",(()=>{o(i.digest("hex"))}))}function J(n){const t=v("md5"),i=o(n);return t.update(i),t.digest("hex")}function N(n,t,o){i(m(n),{recursive:!0},(i=>{if(i)throw i;r(n,JSON.stringify(t),(n=>{if(n)throw n;o()}))}))}function _(n,t){e(m(n),{recursive:!0}),s(n,JSON.stringify(t))}function k(n,t){c(n)&&u(n,"utf8",((n,o)=>{if(n)throw n;t(o)}))}function B(n){if(!c(n))return null;try{return JSON.parse(o(n,"utf8"))}catch(n){return null}}function S(n,t="expires_in"){const o=B(n);if(!o)return null;const i=o[t];if(!i)return o;const{mtimeMs:r}=a(n);if((Date.now()-r)/1e3>i)return null;const e=r+1e3*i;return o.expires_time=e,o}function $(n,t){return t?_(x[n],t):S(x[n])}function C(n,t=g.blackBright){console.log(t(n))}function D(n){const{name:t}=$("APP");return l("/apps",t,n)}function j(n){const{name:t}=$("APP"),o=l("/apps",t);return 0===n.indexOf(o)?n.substring(o.length,n.length):n}function z(o,i,s){let c=0;const u=[];function a(f,p,d){return new Promise(((v,g)=>{if(f>=d)v(void 0);else{p>d-1&&(p=d-1);const P=t(o,{start:f,end:p});let w=Buffer.from([]);P.on("data",(n=>{w=Buffer.concat([w,n])})),P.on("end",(()=>n(this,void 0,void 0,(function*(){const t=l(s,`${h(o)}.${c+1}`);e(m(t),{recursive:!0}),r(t,w,(o=>n(this,void 0,void 0,(function*(){o&&g(o),u.push(t),c+=1,f=p+1,p+=i,yield a(f,p,d),v(void 0)}))))})))),P.on("err",(n=>{g(n)}))}}))}return new Promise(((t,r)=>{f(o,((o,e)=>n(this,void 0,void 0,(function*(){if(o)return r(o);const{size:n}=e;return yield a(0,i-1,n),t(u)}))))}))}export{A,O as C,y as E,x as J,j as a,J as b,_ as c,B as d,S as e,$ as f,C as l,E as m,P as n,k as r,z as s,D as t,w as v,N as w};
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "pcs-cli",
3
+ "description": "Baidu Personal Cloud Storage's Command Line Interface.",
4
+ "version": "1.1.0",
5
+ "type": "module",
6
+ "bin": {
7
+ "pcs": "bin/pcs.js"
8
+ },
9
+ "scripts": {
10
+ "dev": "rollup -cw --watch.onEnd='node ./afterBuildScript.js' --environment NODE_ENV:development",
11
+ "start": "tsc -w",
12
+ "build": "rollup -c --environment NODE_ENV:production",
13
+ "build:esm": "tsc -m es6 --outDir dist/esm",
14
+ "test": "echo \"pre-commit scripts\"",
15
+ "lint:eslint": "eslint \"src/**/*.{ts,js}\" --fix",
16
+ "preversion": "yarn lint:eslint",
17
+ "version": "git add -A .",
18
+ "postversion": "git push && git push --tags"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/sobird/pcs-cli.git"
23
+ },
24
+ "dependencies": {
25
+ "axios": "^1.6.1",
26
+ "bytes": "^3.1.2",
27
+ "chalk": "^5.3.0",
28
+ "cliui": "^8.0.1",
29
+ "commander": "^11.1.0",
30
+ "dayjs": "^1.11.10",
31
+ "glob": "^10.3.10",
32
+ "open": "^9.1.0",
33
+ "progress": "^2.0.3",
34
+ "prompts": "^2.4.2"
35
+ },
36
+ "keywords": [
37
+ "pcs-cli",
38
+ "pcs",
39
+ "baidu",
40
+ "baidu-pcs"
41
+ ],
42
+ "bugs": {
43
+ "url": "https://github.com/sobird/pcs-cli/issues"
44
+ },
45
+ "author": {
46
+ "name": "sobird"
47
+ },
48
+ "license": "MIT",
49
+ "licenses": [
50
+ {
51
+ "type": "MIT",
52
+ "url": "https://github.com/sobird/pcs-cli/blob/master/LICENSE"
53
+ }
54
+ ],
55
+ "readmeFilename": "README.md",
56
+ "homepage": "https://github.com/sobird/pcs-cli",
57
+ "devDependencies": {
58
+ "@commitlint/cli": "^19.2.2",
59
+ "@commitlint/config-conventional": "^19.2.2",
60
+ "@rollup/plugin-commonjs": "^25.0.7",
61
+ "@rollup/plugin-json": "^6.0.1",
62
+ "@rollup/plugin-node-resolve": "^15.2.3",
63
+ "@rollup/plugin-terser": "^0.4.4",
64
+ "@types/bytes": "^3.1.4",
65
+ "@types/node": "^20.9.0",
66
+ "@types/osenv": "^0.1.3",
67
+ "@types/progress": "^2.0.7",
68
+ "@types/prompts": "^2.4.8",
69
+ "esbuild": "^0.19.5",
70
+ "eslint-config-sobird": "^0.2.13",
71
+ "husky": "^9.0.11",
72
+ "jest": "^29.7.0",
73
+ "rollup": "^4.3.0",
74
+ "rollup-plugin-clear": "^2.0.7",
75
+ "rollup-plugin-copy": "^3.5.0",
76
+ "rollup-plugin-esbuild": "^6.1.1",
77
+ "rollup-plugin-peer-deps-external": "^2.2.4",
78
+ "rollup-plugin-typescript2": "^0.36.0",
79
+ "ts-jest": "^29.1.1",
80
+ "tslib": "^2.6.2",
81
+ "typescript": "^5.2.2"
82
+ },
83
+ "publishConfig": {
84
+ "registry": "https://registry.npmjs.org/"
85
+ }
86
+ }
@@ -0,0 +1 @@
1
+ import{_ as e}from"../_tslib-NbJOzQvB.js";import t from"https";import o from"fs";import{dirname as a}from"path";import n from"progress";import"../utils/axios.js";import s from"axios";const r={oauthDevice:e=>s.get("https://openapi.baidu.com/oauth/2.0/device/code",{params:{client_id:e,response_type:"device_code",scope:"basic,netdisk"}}),oauthToken:(e,t,o)=>s.get("https://openapi.baidu.com/oauth/2.0/token",{params:{client_id:e,client_secret:t,code:o,grant_type:"device_token",scope:"basic,netdisk"}}),refreshToken:(e,t,o)=>s.get("https://openapi.baidu.com/oauth/2.0/token",{params:{client_id:e,client_secret:t,refresh_token:o,grant_type:"refresh_token"}}),quotaInfo:e=>s.get("/pcs/quota",{params:{method:"info",access_token:e}}),getMeta:(e,t)=>s.get("/pcs/file",{params:{method:"meta",access_token:e,path:t}}),listFile:(e,t)=>s.get("/pcs/file",{params:{method:"list",access_token:e,path:t}}),download(t,r,i){return e(this,void 0,void 0,(function*(){o.mkdirSync(a(i),{recursive:!0});const e=o.createWriteStream(i),{data:p,headers:c}=yield s.get("/pcs/file",{params:{method:"download",access_token:t,path:r},responseType:"stream",responseParser:e=>e}),d=c["content-length"],m=new n(" downloading [:bar] :rate/bps :percent :etas",{complete:"=",incomplete:" ",width:40,total:parseInt(d,10)});return p.on("data",(e=>m.tick(e.length))),p.pipe(e),new Promise(((t,o)=>{e.on("finish",t),e.on("error",o)}))}))},upload2(a,s,r,i="overwrite",p){return e(this,void 0,void 0,(function*(){let e=`/rest/2.0/pcs/file?method=upload&access_token=${a}&path=${encodeURIComponent(r)}&ondup=${i}`;p&&(e=`${e}&type=${p}`);const c=o.statSync(s),d=Math.random().toString(16),m=`--${d}\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name="file"; filename="${r}"\r\n\r\n`,h=`\r\n--${d}--`,l=Buffer.byteLength(m)+Buffer.byteLength(h)+c.size,f=new n("[:bar] :rate/bps :percent :etas",{complete:"=",incomplete:" ",width:40,total:c.size});return new Promise(((a,n)=>{const r=t.request({hostname:"pcs.baidu.com",method:"POST",path:e},(e=>{e.on("data",(e=>{a(JSON.parse(e))})),e.on("end",(()=>{})),e.on("error",(e=>{n(e)}))}));r.setHeader("Content-Type",`multipart/form-data; boundary=${d}`),r.setHeader("Content-Length",l),r.write(m);const i=o.createReadStream(s);i.pipe(r,{end:!1}),i.on("end",(()=>{r.end(h)})),i.on("data",(e=>{f.tick(e.length)}))}))}))},delete:(e,t)=>s.get("/pcs/file",{params:{method:"delete",access_token:e,path:t}}),fetch:(e,t,o)=>s.get("/pcs/services/cloud_dl",{params:{method:"add_task",access_token:e,save_path:o,source_url:t}}),createSuperFile:(e,t,o)=>s.get("/pcs/file",{params:{method:"createsuperfile",access_token:e,path:t,param:JSON.stringify(o)}})};export{r as default};
package/utils/axios.js ADDED
@@ -0,0 +1 @@
1
+ import e from"axios";export{default}from"axios";e.defaults.withCredentials=!0,e.defaults.timeout=1e4,e.defaults.baseURL="https://pcs.baidu.com/rest/2.0",e.interceptors.request.use((e=>e),(e=>Promise.reject(e))),e.interceptors.response.use((e=>{const{config:s,data:r}=e;return s.responseParser?s.responseParser(e):r}),(e=>{const{request:s,response:r}=e;return r&&r.status,Promise.reject(e)}));
package/utils/index.js ADDED
@@ -0,0 +1 @@
1
+ import"../_tslib-NbJOzQvB.js";import"fs";import"os";import"path";import"crypto";import"chalk";export{A as APP_LIST_URL,C as CREATE_APP_URL,E as EXPIRES_IN,J as JSON_TMP,f as fileJSON,l as log,m as md5File,b as md5FileSync,r as readJson,d as readJsonSync,e as readUnexpiredJsonSync,s as splitFile,a as toLocalPath,t as toRemotePath,w as writeJson,c as writeJsonSync}from"../index-7szJY7Td.js";