mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 15:19:00 +08:00
Minor changes
This commit is contained in:
parent
c389aa19a2
commit
0e46d8e14d
@ -18,6 +18,6 @@ console.log(
|
|||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
import serve from './facade';
|
import serve from './restful';
|
||||||
|
|
||||||
serve();
|
serve();
|
||||||
|
@ -9,14 +9,14 @@ export default async function download(url, ua) {
|
|||||||
return cache.get(id);
|
return cache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const $http = HTTP({
|
const http = HTTP({
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': ua,
|
'User-Agent': ua,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = new Promise((resolve, reject) => {
|
const result = new Promise((resolve, reject) => {
|
||||||
$http.get(url).then((resp) => {
|
http.get(url).then((resp) => {
|
||||||
const body = resp.body;
|
const body = resp.body;
|
||||||
if (body.replace(/\s/g, '').length === 0)
|
if (body.replace(/\s/g, '').length === 0)
|
||||||
reject(new Error('订阅内容为空!'));
|
reject(new Error('订阅内容为空!'));
|
||||||
|
@ -3,8 +3,9 @@ import { HTTP } from './open-api';
|
|||||||
/**
|
/**
|
||||||
* Gist backup
|
* Gist backup
|
||||||
*/
|
*/
|
||||||
export default function Gist({ token, key }) {
|
export default class Gist {
|
||||||
const http = HTTP({
|
constructor({ token, key }) {
|
||||||
|
this.http = HTTP({
|
||||||
baseURL: 'https://api.github.com',
|
baseURL: 'https://api.github.com',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${token}`,
|
Authorization: `token ${token}`,
|
||||||
@ -23,12 +24,14 @@ export default function Gist({ token, key }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
async function locate() {
|
async locate() {
|
||||||
return http.get('/gists').then((response) => {
|
return this.http.get('/gists').then((response) => {
|
||||||
const gists = JSON.parse(response.body);
|
const gists = JSON.parse(response.body);
|
||||||
for (let g of gists) {
|
for (let g of gists) {
|
||||||
if (g.description === key) {
|
if (g.description === this.key) {
|
||||||
return g.id;
|
return g.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,42 +39,42 @@ export default function Gist({ token, key }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.upload = async function (files) {
|
async upload(files) {
|
||||||
const id = await locate();
|
const id = await this.locate();
|
||||||
|
|
||||||
if (id === -1) {
|
if (id === -1) {
|
||||||
// create a new gist for backup
|
// create a new gist for backup
|
||||||
return http.post({
|
return this.http.post({
|
||||||
url: '/gists',
|
url: '/gists',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
description: key,
|
description: this.key,
|
||||||
public: false,
|
public: false,
|
||||||
files,
|
files,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// update an existing gist
|
// update an existing gist
|
||||||
return http.patch({
|
return this.http.patch({
|
||||||
url: `/gists/${id}`,
|
url: `/gists/${id}`,
|
||||||
body: JSON.stringify({ files }),
|
body: JSON.stringify({ files }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
this.download = async function (filename) {
|
async download(filename) {
|
||||||
const id = await locate();
|
const id = await this.locate();
|
||||||
if (id === -1) {
|
if (id === -1) {
|
||||||
return Promise.reject('未找到Gist备份!');
|
return Promise.reject('未找到Gist备份!');
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const { files } = await http
|
const { files } = await this.http
|
||||||
.get(`/gists/${id}`)
|
.get(`/gists/${id}`)
|
||||||
.then((resp) => JSON.parse(resp.body));
|
.then((resp) => JSON.parse(resp.body));
|
||||||
const url = files[filename].raw_url;
|
const url = files[filename].raw_url;
|
||||||
return await http.get(url).then((resp) => resp.body);
|
return await this.http.get(url).then((resp) => resp.body);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
4
backend/sub-store.min.js
vendored
4
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user