Skip to content

Commit 5978191

Browse files
committed
add basename
1 parent 137ac5f commit 5978191

File tree

14 files changed

+169
-21
lines changed

14 files changed

+169
-21
lines changed

Docker-compose.yml

Whitespace-only changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ function cookie_decrypt( uuid, encrypted, password )
7878
}
7979
```
8080

81-
extension/function.js 查看更多
81+
extension/function.js 查看更多

RoboFile.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,26 @@
66
*/
77
class RoboFile extends \Robo\Tasks
88
{
9-
// define public methods as commands
10-
public function buildDev()
9+
public function apiDev()
1110
{
12-
$this->_exec("cd extension && npx browserslist@latest --update-db && yarn build");
11+
$this->_exec("cd api && node_modules/nodemon/bin/nodemon.js app.js");
12+
}
13+
14+
public function imagePub($uniqid = null)
15+
{
16+
if ($uniqid == null) {
17+
$uniqid = date("Y.m.d.H.i");
18+
;
19+
}
20+
21+
$this->_exec("docker buildx create --use --name build-node-example --driver docker-container");
22+
$this->_exec("docker buildx build -t easychen/cookiecloud:latest -t easychen/cookiecloud:$uniqid --platform=linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x --push ./docker");
23+
$this->_exec("docker buildx rm build-node-example");
24+
25+
}
26+
27+
public function extBuild()
28+
{
29+
$this->_exec("cd extension && pnpm build && pnpm package");
1330
}
1431
}

api/app.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const data_dir = path.join(__dirname, 'data');
1111
if (!fs.existsSync(data_dir)) fs.mkdirSync(data_dir);
1212

1313
var multer = require('multer');
14-
var forms = multer({limits: { fieldSize: 100 * 1024 * 1024 }});
14+
var forms = multer({limits: { fieldSize: 100*1024*1024 }});
1515
const bodyParser = require('body-parser')
1616
app.use(bodyParser.json());
1717
app.use(forms.array());
1818
app.use(bodyParser.urlencoded({ extended: true }));
19+
app.use(bodyParser.json({limit : 100*1024*1024 }));
1920

2021
app.all(`/`, (req, res) => {
2122
res.send('Hello World!');
@@ -31,7 +32,7 @@ app.post(`/update`, (req, res) => {
3132
}
3233

3334
// save encrypted to uuid file
34-
const file_path = path.join(data_dir, uuid+'.json');
35+
const file_path = path.join(data_dir, path.basename(uuid)+'.json');
3536
const content = JSON.stringify({"encrypted":encrypted});
3637
fs.writeFileSync(file_path, content);
3738
if( fs.readFileSync(file_path) == content )
@@ -48,7 +49,7 @@ app.all(`/get/:uuid`, (req, res) => {
4849
return;
4950
}
5051
// get encrypted from uuid file
51-
const file_path = path.join(data_dir, uuid+'.json');
52+
const file_path = path.join(data_dir, path.basename(uuid)+'.json');
5253
if (!fs.existsSync(file_path)) {
5354
res.status(404).send('Not Found');
5455
return;
@@ -70,8 +71,6 @@ app.all(`/get/:uuid`, (req, res) => {
7071
{
7172
res.json(data);
7273
}
73-
74-
7574
}
7675
});
7776

design/logo.xd

1.31 MB
Binary file not shown.

docker/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM --platform=$TARGETPLATFORM node:16-alpine3.15
2+
EXPOSE 8088
3+
RUN mkdir -p /data/api
4+
COPY app.js /data/api/app.js
5+
COPY package.json /data/api/package.json
6+
RUN npm install --prefix /data/api
7+
CMD ["node", "/data/api/app.js"]

docker/app.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const app = express();
5+
6+
const cors = require('cors');
7+
app.use(cors());
8+
9+
const data_dir = path.join(__dirname, 'data');
10+
// make dir if not exist
11+
if (!fs.existsSync(data_dir)) fs.mkdirSync(data_dir);
12+
13+
var multer = require('multer');
14+
var forms = multer({limits: { fieldSize: 100*1024*1024 }});
15+
const bodyParser = require('body-parser')
16+
app.use(bodyParser.json());
17+
app.use(forms.array());
18+
app.use(bodyParser.urlencoded({ extended: true }));
19+
app.use(bodyParser.json({limit : 100*1024*1024 }));
20+
21+
app.all(`/`, (req, res) => {
22+
res.send('Hello World!');
23+
});
24+
25+
app.post(`/update`, (req, res) => {
26+
// {"encrypted":"123","uuid":String(short_uid.generate())}
27+
const { encrypted, uuid } = req.body;
28+
// none of the fields can be empty
29+
if (!encrypted || !uuid) {
30+
res.status(400).send('Bad Request');
31+
return;
32+
}
33+
34+
// save encrypted to uuid file
35+
const file_path = path.join(data_dir, path.basename(uuid)+'.json');
36+
const content = JSON.stringify({"encrypted":encrypted});
37+
fs.writeFileSync(file_path, content);
38+
if( fs.readFileSync(file_path) == content )
39+
res.json({"action":"done"});
40+
else
41+
res.json({"action":"error"});
42+
});
43+
44+
app.all(`/get/:uuid`, (req, res) => {
45+
const { uuid } = req.params;
46+
// none of the fields can be empty
47+
if (!uuid) {
48+
res.status(400).send('Bad Request');
49+
return;
50+
}
51+
// get encrypted from uuid file
52+
const file_path = path.join(data_dir, path.basename(uuid)+'.json');
53+
if (!fs.existsSync(file_path)) {
54+
res.status(404).send('Not Found');
55+
return;
56+
}
57+
const data = JSON.parse(fs.readFileSync(file_path));
58+
if( !data )
59+
{
60+
res.status(500).send('Internal Serverless Error');
61+
return;
62+
}
63+
else
64+
{
65+
// 如果传递了password,则返回解密后的数据
66+
if( req.body.password )
67+
{
68+
const parsed = cookie_decrypt( uuid, data.encrypted, req.body.password );
69+
res.json(parsed);
70+
}else
71+
{
72+
res.json(data);
73+
}
74+
}
75+
});
76+
77+
78+
app.use(function (err, req, res, next) {
79+
console.error(err);
80+
res.status(500).send('Internal Serverless Error');
81+
});
82+
83+
84+
const port = 8088;
85+
app.listen(port, () => {
86+
console.log(`Server start on http://localhost:${port}`);
87+
});
88+
89+
function cookie_decrypt( uuid, encrypted, password )
90+
{
91+
const CryptoJS = require('crypto-js');
92+
const the_key = CryptoJS.MD5(uuid+'-'+password).toString().substring(0,16);
93+
const decrypted = CryptoJS.AES.decrypt(encrypted, the_key).toString(CryptoJS.enc.Utf8);
94+
const parsed = JSON.parse(decrypted);
95+
return parsed;
96+
}
97+

docker/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dependencies": {
3+
"body-parser": "^1.20.1",
4+
"cors": "^2.8.5",
5+
"crypto-js": "^4.1.1",
6+
"express": "^4.18.2",
7+
"fs": "^0.0.1-security",
8+
"multer": "^1.4.5-lts.1",
9+
"path": "^0.12.7"
10+
},
11+
"devDependencies": {
12+
"nodemon": "^2.0.20"
13+
}
14+
}

extension/background/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ chrome.alarms.onAlarm.addListener( async a =>
7575

7676

7777
}
78-
});
78+
});

extension/background/messages/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export type RequestBody = {
77
}
88

99
export type ResponseBody = {
10-
message: string
10+
message: string,
11+
note: string|null,
1112
}
1213

1314
export const handler: PlasmoMessaging.MessageHandler<RequestBody,
@@ -16,7 +17,8 @@ ResponseBody> = async (req, res) => {
1617
const payload = req.body.payload;
1718
const result = (payload['type'] && payload['type'] == 'down') ? await download_cookie(payload) : await upload_cookie(payload);
1819
res.send({
19-
message: result['action']
20+
message: result['action'],
21+
note: result['note'],
2022
})
2123
}
2224

extension/function.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export async function upload_cookie( payload )
6060
const endpoint = payload['endpoint'].trim().replace(/\/+$/, '')+'/update';
6161

6262
// get sha256 of the encrypted data
63-
const sha256 = CryptoJS.SHA256(uuid+"-"+endpoint+"-"+JSON.stringify(cookies)).toString();
63+
const sha256 = CryptoJS.SHA256(uuid+"-"+password+"-"+endpoint+"-"+JSON.stringify(cookies)).toString();
6464
console.log( "sha256", sha256 );
6565
const last_uploaded_info = await load_data( 'LAST_UPLOADED_COOKIE' );
6666
// 如果24小时内已经上传过同样内容的数据,则不再上传
6767
if( last_uploaded_info && last_uploaded_info.sha256 === sha256 && new Date().getTime() - last_uploaded_info.timestamp < 1000*60*60*24 )
6868
{
69-
console.log("same data in 24 hours, skip");
70-
return {action:'done'};
69+
console.log("same data in 24 hours, skip1");
70+
return {action:'done',note:'本地Cookie数据无变动,不再上传'};
7171
}
7272

7373
const payload2 = {
@@ -205,4 +205,4 @@ function buildUrl(secure, domain, path)
205205
domain = domain.substr(1);
206206
}
207207
return `http${secure ? 's' : ''}://${domain}${path}`;
208-
}
208+
}

extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cookie-cloud",
33
"displayName": "CookieCloud",
44
"description": "__MSG_appDesc__",
5-
"version": "0.1.2",
5+
"version": "0.1.3",
66
"default_locale": "zh_CN",
77
"author": "[email protected]",
88
"license": "GPLv3",

extension/pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extension/popup.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { RadioChangeEvent } from 'antd';
1010
import { Radio } from 'antd';
1111

1212
function IndexPopup() {
13-
let init: Object={"endpoint":"http://127.0.0.1:8088","password":"123","interval":10,"domains":".jd.com","uuid":String(short_uid.generate()),"type":"up"};
13+
let init: Object={"endpoint":"http://127.0.0.1:8088","password":"123","interval":10,"domains":"","uuid":String(short_uid.generate()),"type":"up"};
1414
const [data, setData] = useState(init);
1515

1616
async function test()
@@ -20,7 +20,10 @@ function IndexPopup() {
2020
console.log("ret888...",ret);
2121
if( ret && ret['message'] == 'done' )
2222
{
23-
alert('测试成功');
23+
if( ret['note'] )
24+
alert(ret['note']);
25+
else
26+
alert('测试成功');
2427
}else
2528
{
2629
alert('测试失败,请检查填写的信息是否正确');
@@ -90,8 +93,9 @@ function IndexPopup() {
9093
<input type="text" className="border-1 my-2 p-2 rounded w-full" placeholder="丢失后数据失效,请妥善保管" value={data['password']} onChange={e=>onChange('password',e)}/>
9194
<div className="">同步时间间隔·分钟</div>
9295
<input type="number" className="border-1 my-2 p-2 rounded w-full" placeholder="最少10分钟" value={data['interval']} onChange={e=>onChange('interval',e)} />
93-
<div className="">同步域名</div>
94-
<textarea className="border-1 my-2 p-2 rounded w-full" style={{"height":"120px"}} placeholder="一行一个,支持.domain子域名匹配,留空默认同步全部" onChange={e=>onChange('domains',e)} value={data['domains']}/>
96+
{data['type'] && data['type'] == 'up' && <><div className="">同步域名关键词</div>
97+
<textarea className="border-1 my-2 p-2 rounded w-full" style={{"height":"120px"}} placeholder="一行一个,同步包含关键词的全部域名,如qq.com,jd.com会包含全部子域名,留空默认同步全部" onChange={e=>onChange('domains',e)} value={data['domains']}/>
98+
</>}
9599
<div className="flex flex-row justify-between mt-2">
96100
<div className="left text-gray-400">
97101
<Button className="hover:bg-blue-100" onClick={()=>test()}>测试</Button>

0 commit comments

Comments
 (0)