pcs-cli 1.1.0 → 1.3.2
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.
Potentially problematic release.
This version of pcs-cli might be problematic. Click here for more details.
- package/dist/pcs.js +2 -0
- package/package.json +30 -25
- package/_tslib-NbJOzQvB.js +0 -1
- package/bin/pcs.js +0 -2
- package/command/delete.js +0 -1
- package/command/download.js +0 -1
- package/command/fetch.js +0 -1
- package/command/init.js +0 -1
- package/command/list.js +0 -1
- package/command/meta.js +0 -1
- package/command/quota.js +0 -1
- package/command/refresh.js +0 -1
- package/command/upload.js +0 -1
- package/index-7szJY7Td.js +0 -1
- package/services/pcs.js +0 -1
- package/utils/axios.js +0 -1
- package/utils/index.js +0 -1
package/dist/pcs.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{Command as e}from"@commander-js/extra-typings";import t from"chalk";import o,{mkdtempSync as r,statSync as n,mkdirSync as a,createReadStream as s,createWriteStream as i,existsSync as c}from"fs";import p from"open";import d from"prompts";import l from"axios";import"crypto";import m,{tmpdir as u}from"os";import h,{basename as f,join as g,sep as y,dirname as w,relative as k}from"path";import{pipeline as _}from"stream/promises";import{homedir as b}from"node:os";import $ from"node:path";import{promises as v}from"node:fs";import x from"bytes";import S from"cliui";import C from"dayjs";import O from"progress";import{glob as z}from"glob";import{sep as T,join as E}from"node:path/posix";import N from"https";class B{config;axios;constructor(e){this.config=e,this.config={scope:"basic,netdisk",...e},this.axios=l.create({timeout:1e4})}async getUserInfo(e){const{data:t}=await l.get("https://pan.baidu.com/rest/2.0/xpan/nas",{params:{method:"uinfo",access_token:e}});return t}async refreshToken(e){const{client_secret:t,client_id:o}=this.config,{data:r}=await l.get("https://openapi.baidu.com/oauth/2.0/token",{params:{grant_type:"refresh_token",client_id:o,client_secret:t,refresh_token:e}});return r}}class P extends B{constructor(e){super({...e,response_type:"device_code"})}async getDeviceCode(){const{data:e}=await this.axios.get("https://openapi.baidu.com/oauth/2.0/device/code",{params:{response_type:"device_code",client_id:this.config.client_id,scope:this.config.scope}});return e}getAuthorizeURL(e){return`${e.verification_url}?code=${e.user_code}`}async authorize(e){const{client_id:t,client_secret:o,scope:r}=this.config,{data:n}=await this.axios.get("https://openapi.baidu.com/oauth/2.0/token",{params:{grant_type:"device_token",code:e,client_id:t,client_secret:o,scope:r}});return n}}function q(e,t){return`]8;;${t}${e}]8;;`}const I=$.join(b(),".pcs"),V=$.join(I,"config.json"),D="https://pan.baidu.com/union/console/createapp";async function L(e,t){try{const o=h.dirname(e);await v.mkdir(o,{recursive:!0}),await v.writeFile(e,JSON.stringify(t,null,2),"utf8")}catch(e){if(e instanceof Error)throw new Error(`写入文件失败: ${e.message}`)}}const j=new e("init").description("initialize baidu pcs").option("-n, --name <string>","app name","").option("-k, --key <string>","app key","").option("-s, --secret <string>","app secret","").action(async e=>{if(c(V)){const{confirm:e}=await d({type:"confirm",name:"confirm",message:"Baidu pcs initialization will be begin. If you have already configured before, your old settings will be overwritten. Can you confirm?",initial:!1});if(!e)return}const o=[];if(["name","key","secret"].forEach(t=>{e[t]||o.push({type:"text",name:t,message:`Please enter baidu app ${t}`})}),!(e={...e,...await d(o)}).key||!e.secret)return;const r=await async function(e){const o=new P({client_id:e.key,client_secret:e.secret}),r=await o.getDeviceCode(),n=o.getAuthorizeURL(r);console.log("Launch your favorite web browser and visit: "),console.log(q(n,n)),console.log(`Input ${t.bold.red(r.user_code)} as the user code if asked.`),console.log("After granting access to the application, come back here and "),await p(n);const{confirm:a}=await d({type:"confirm",name:"confirm",message:"Press Enter to continue",initial:!0});if(a){const e=await o.authorize(r.device_code);return console.log(t.green("Successfully initialized")),console.log(`access_token: ${t.yellowBright(e.access_token)}`),console.log(`refresh_token: ${t.yellowBright(e.refresh_token)}`),e}}(e);r&&await L(V,{...e,...r})}),A=new e("list").description("list directory contents").argument("[path]","path","/").alias("ll").option("-t --token <token>","access token","").action(async(e,o,r)=>{const{pcs:n}=r;try{const o=S({}),{list:r}=await n.list(e);r.map(e=>{const{server_mtime:r,size:n,server_filename:a,isdir:s}=e,i=1===s?t.blueBright(a):a;return o.div({text:t.gray(C.unix(r).format("YYYY/MM/DD HH:mm:ss")),width:22,padding:[0,0,0,0]},{text:x(n),width:15,align:"right",padding:[0,2,0,0]},{text:i,padding:[0,0,0,0]}),e}),console.log(o.toString())}catch(e){const{response:{data:o}}=e;console.error(t.red(`error code ${o.error_code} : ${o.error_msg}`))}}),U=new e("meta").description("get path meta").argument("[path]","meta path","/").option("-t --token [token]","access token").action(async(e,o,r)=>{const{pcs:n}=r;try{const{list:t}=await n.meta(e);console.log(t[0])}catch(e){const{response:{data:o}}=e;console.log(t.red(`error code ${o.error_code}: ${o.error_msg}`))}}),Y=new e("quota").description("check your pcs status").option("-t --token [token]","access token").action(async(e,o)=>{const{pcs:r}=o;try{const{quota:e,used:o}=await r.quota();new O(":bar :used/:quota :percent",{complete:"█",incomplete:t.green("░"),width:30,total:e}).tick(o,{used:x(o),quota:x(e)}),console.log("")}catch(e){const{response:{data:o}}=e;console.log(t.red`error code ${o.error_code} : ${o.error_msg}`)}}),F=new e("fetch").description("fetch source to remote").argument("[source]","source path",y).argument("[remote]","remote path",".").option("-t --token <token>","access token","").action(async(e,o,r,n)=>{const{pcs:a}=n;try{await a.fetch(e,o)}catch(e){const{response:{data:o}}=e;console.log(t.red(`error code ${o.error_code} : ${o.error_msg}`))}}),J=new e("delete").alias("rm").description("delete remote file").argument("<remote>","remote path").option("-t --token <token>","access token","").action(async(e,o,r)=>{const{pcs:n}=r;if(n.resolve(e)===n.resolve("/")){console.log(t.red("You are about to delete the root directory of the application, which will lose all data"));const{confirm:e}=await d({type:"confirm",name:"confirm",message:"Are you sure you want to continue?",initial:!1});if(!e)return}try{await n.delete(e)}catch(e){const{response:{data:o}}=e;console.log(t.red(`error code ${o.error_code} : ${o.error_msg}`))}}),M=new e("upload").description("upload local file").argument("[pattern]","glob pattern","*").argument("[remote]","remote path",y).option("-t --token [token]","access token").option("-b --bytes <number>","Split upload bytes size",Number,1073741824).option("--thread","Thread").action(async(e,o,c,p)=>{const{pcs:d}=p,l=await z(e,{nodir:!0}),{bytes:h}=c,y=g(m.tmpdir(),"pcs-cli");try{l.reduce(async(e,c)=>{await e;const p=n(c);if(Number.isInteger(h)&&p.size>h){const e=await async function(e,t,o=r(g(u(),"splitFile-"))){if(!e||"string"!=typeof e)throw new TypeError("path must be a non-empty string");if(!Number.isInteger(t)||t<=0)throw new TypeError("chunkSize must be a positive integer");if(!o||"string"!=typeof o)throw new TypeError("outputDir must be a non-empty string");const c=[],{size:p}=n(e),d=f(e);a(o,{recursive:!0});for(let r=0;r<p;r+=t){const n=Math.min(r+t-1,p-1),a=g(o,`${d}.${c.length+1}`),l=s(e,{start:r,end:n}),m=i(a);await _(l,m),c.push(a)}return c}(c,h,y),t=[];for(const o of e){const{md5:e}=await d.upload(o,"","overwrite","tmpfile");t.push(e)}const p={block_list:t};return d.createSuperFile(g(o,c),p)}return console.log(`${t.blueBright("==>")} Uploading ${c}`),d.upload(c,g(o,c))},Promise.resolve())}catch(e){const{response:{data:t}}=e;console.log(`error code ${t.error_code} : ${t.error_msg}`)}}),R=new e("refresh").description("refresh token").option("-k, --key <string>","app key","").option("-s, --secret <string>","app secret","").option("-t --refresh-token <refresh token>","refresh token","").action(async e=>{const o=new P({client_id:e.key,client_secret:e.secret});try{const r=await o.refreshToken(e.refreshToken);await L(V,{...e,...r}),console.log(t.green("Successfully refreshed token"))}catch(e){const{response:{data:o}}=e;console.log(t.red(`OAuth error ${o.error} : ${o.error_description}`))}}),H=new e("download").alias("dl").description("download remote file").argument("[remote]","remote path",T).argument("[local]","local path",".").option("-t --token <token>","access token","").action(async(e,o,r,n)=>{const{pcs:a}=n;try{const{list:r}=await a.list(e);r.reduce(async(e,r)=>{await e;const n=E(o,a.normalize(r.path));return 1===r.isdir?Promise.resolve():(console.log(`${t.blueBright("==>")} Downloading ${t.green(n)}`),a.download(r.path,n))},Promise.resolve())}catch(e){const{response:{data:o}}=e;console.log(t.red(`error code ${o.error_code||o.statusCode} : ${o.error_msg||o.statusMessage}`))}});class W{name;token;axios;constructor(e,t){this.name=e,this.token=t,this.axios=l.create({timeout:1e4,baseURL:"https://pcs.baidu.com/rest/2.0"})}async quota(){const{data:e}=await this.axios.get("/pcs/quota",{params:{method:"info",access_token:this.token}});return e}async meta(e){const{data:t}=await this.axios.get("/pcs/file",{params:{method:"meta",access_token:this.token,path:this.resolve(e)}});return t}async list(e){const{data:t}=await this.axios.get("/pcs/file",{params:{method:"list",access_token:this.token,path:this.resolve(e)}});return t}async delete(e){const{data:t}=await l.get("/pcs/file",{params:{method:"delete",access_token:this.token,path:this.resolve(e)}});return t}async fetch(e,t){const{data:o}=await l.get("/pcs/services/cloud_dl",{params:{method:"add_task",access_token:this.token,save_path:this.resolve(t),source_url:e}});return o}async download(e,t){o.mkdirSync(w(t),{recursive:!0});const r=o.createWriteStream(t),{data:n,headers:a}=await this.axios.get("/pcs/file",{params:{method:"download",access_token:this.token,path:this.resolve(e)},responseType:"stream"}),s=a["content-length"],i=new O(" downloading [:bar] :rate/bps :percent :etas",{complete:"=",incomplete:" ",width:40,total:parseInt(s,10)});return n.on("data",e=>i.tick(e.length)),n.pipe(r),new Promise((e,t)=>{r.on("finish",e),r.on("error",t)})}async upload(e,t,r="overwrite",n){let a=`/rest/2.0/pcs/file?method=upload&access_token=${this.token}&path=${encodeURIComponent(t)}&ondup=${r}`;n&&(a=`${a}&type=${n}`);const s=o.statSync(e),i=Math.random().toString(16),c=`--${i}\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name="file"; filename="${t}"\r\n\r\n`,p=`\r\n--${i}--`,d=Buffer.byteLength(c)+Buffer.byteLength(p)+s.size,l=new O("[:bar] :rate/bps :percent :etas",{complete:"=",incomplete:" ",width:40,total:s.size});return new Promise((t,r)=>{const n=N.request({hostname:"pcs.baidu.com",method:"POST",path:a},e=>{e.on("data",e=>{t(JSON.parse(e))}),e.on("end",()=>{}),e.on("error",e=>{r(e)})});n.setHeader("Content-Type",`multipart/form-data; boundary=${i}`),n.setHeader("Content-Length",d),n.write(c);const s=o.createReadStream(e);s.pipe(n,{end:!1}),s.on("end",()=>{n.end(p)}),s.on("data",e=>{l.tick(e.length)})})}async createSuperFile(e,t){const{data:o}=await l.get("/pcs/file",{params:{method:"createsuperfile",access_token:this.token,path:e,param:JSON.stringify(t)}});return o}get rootdir(){return g("/apps",this.name)}resolve(e){return g(this.rootdir,e)}normalize(e){return k(this.rootdir,e)}}const G=new e("pcs-cli").description(`Baidu Personal Cloud Storage Scaffold.\n\nYou can get app key by visit ${q(D,D)}.\nIf you have already created an app, you can visit ${t.blue.underline("https://pan.baidu.com/union/console/applist")} and get it in your app's info.`).version("1.3.2").hook("preAction",async(e,t)=>{const o=t.name();if("init"!==o)try{const e=await async function(e){try{return JSON.parse(await v.readFile(e,"utf8"))}catch(t){if(t instanceof Error&&"code"in t&&"ENOENT"===t.code)throw new Error(`文件不存在: ${e}`);if(t instanceof SyntaxError)throw new Error(`JSON 格式错误: ${t.message}`);throw t}}(V);"refresh"===o?(t.setOptionValue("key",t.getOptionValue("key")||e.key),t.setOptionValue("secret",t.getOptionValue("secret")||e.secret),t.setOptionValue("refreshToken",t.getOptionValue("refreshToken")||e.refresh_token)):t.pcs=new W(t.getOptionValue("name")||e.name,t.getOptionValue("token")||e.access_token)}catch(e){}});G.addCommand(j).addCommand(A).addCommand(U).addCommand(Y).addCommand(F).addCommand(J).addCommand(M).addCommand(R).addCommand(H);try{G.exitOverride(),G.parse(process.argv)}catch(e){}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pcs-cli",
|
|
3
3
|
"description": "Baidu Personal Cloud Storage's Command Line Interface.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"pcs": "
|
|
7
|
+
"pcs": "dist/pcs.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "rollup -cw --watch.onEnd='node ./afterBuildScript.js' --environment NODE_ENV:development",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"build:esm": "tsc -m es6 --outDir dist/esm",
|
|
14
14
|
"test": "echo \"pre-commit scripts\"",
|
|
15
15
|
"lint:eslint": "eslint \"src/**/*.{ts,js}\" --fix",
|
|
16
|
-
"
|
|
16
|
+
"prepublishOnly": "tsx scripts/prepublish.ts",
|
|
17
|
+
"preversion": "npm run lint:eslint",
|
|
17
18
|
"version": "git add -A .",
|
|
18
19
|
"postversion": "git push && git push --tags"
|
|
19
20
|
},
|
|
@@ -21,18 +22,6 @@
|
|
|
21
22
|
"type": "git",
|
|
22
23
|
"url": "git+https://github.com/sobird/pcs-cli.git"
|
|
23
24
|
},
|
|
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
25
|
"keywords": [
|
|
37
26
|
"pcs-cli",
|
|
38
27
|
"pcs",
|
|
@@ -54,33 +43,49 @@
|
|
|
54
43
|
],
|
|
55
44
|
"readmeFilename": "README.md",
|
|
56
45
|
"homepage": "https://github.com/sobird/pcs-cli",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
48
|
+
"axios": "^1.6.1",
|
|
49
|
+
"bytes": "^3.1.2",
|
|
50
|
+
"chalk": "^5.3.0",
|
|
51
|
+
"cliui": "^8.0.1",
|
|
52
|
+
"commander": "^14.0.2",
|
|
53
|
+
"dayjs": "^1.11.10",
|
|
54
|
+
"glob": "^13.0.0",
|
|
55
|
+
"open": "^9.1.0",
|
|
56
|
+
"progress": "^2.0.3",
|
|
57
|
+
"prompts": "^2.4.2"
|
|
58
|
+
},
|
|
57
59
|
"devDependencies": {
|
|
58
60
|
"@commitlint/cli": "^19.2.2",
|
|
59
61
|
"@commitlint/config-conventional": "^19.2.2",
|
|
60
62
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
61
|
-
"@rollup/plugin-json": "^6.0
|
|
63
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
62
64
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
65
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
63
66
|
"@rollup/plugin-terser": "^0.4.4",
|
|
67
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
64
68
|
"@types/bytes": "^3.1.4",
|
|
65
69
|
"@types/node": "^20.9.0",
|
|
66
70
|
"@types/osenv": "^0.1.3",
|
|
67
71
|
"@types/progress": "^2.0.7",
|
|
68
72
|
"@types/prompts": "^2.4.8",
|
|
69
|
-
"esbuild": "^0.
|
|
70
|
-
"eslint-config-sobird": "^0.2.
|
|
73
|
+
"esbuild": "^0.27.2",
|
|
74
|
+
"eslint-config-sobird": "^0.2.16",
|
|
71
75
|
"husky": "^9.0.11",
|
|
72
|
-
"
|
|
73
|
-
"rollup": "^4.3.0",
|
|
76
|
+
"rollup": "^4.54.0",
|
|
74
77
|
"rollup-plugin-clear": "^2.0.7",
|
|
75
78
|
"rollup-plugin-copy": "^3.5.0",
|
|
76
79
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
77
80
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"typescript": "^5.2.2"
|
|
81
|
+
"tsx": "^4.21.0",
|
|
82
|
+
"typescript": "^5.9.3",
|
|
83
|
+
"vitest": "^4.0.15"
|
|
82
84
|
},
|
|
85
|
+
"files": [
|
|
86
|
+
"dist"
|
|
87
|
+
],
|
|
83
88
|
"publishConfig": {
|
|
84
89
|
"registry": "https://registry.npmjs.org/"
|
|
85
90
|
}
|
|
86
|
-
}
|
|
91
|
+
}
|
package/_tslib-NbJOzQvB.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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();
|
package/command/delete.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/download.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/fetch.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/init.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/list.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/meta.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/quota.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/refresh.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/command/upload.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/index-7szJY7Td.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/services/pcs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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";
|