Skip to content

Commit

Permalink
add 0.3.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
acgotaku committed Jun 10, 2018
1 parent 9c5c572 commit 99f7acd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
10 changes: 6 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// Promise style `chrome.cookies.get()`
const getCookie = (detail) => {
return new Promise(function (resolve) {
chrome.cookies.get(detail, resolve)
chrome.cookies.getAll(detail, resolve)
})
}

Expand All @@ -56,9 +56,11 @@ const getCookies = (details) => {
const list = details.map(item => getCookie(item))
Promise.all(list).then(function (cookies) {
let obj = {}
for (let item of cookies) {
if (item !== null) {
obj[item.name] = item.value
for (let cookie of cookies) {
for (let item of cookie) {
if (item !== null) {
obj[item.name] = item.value
}
}
}
resolve(obj)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"manifest_version": 2,
"permissions": [ "cookies", "storage", "tabs", "*://*.115.com/*"],
"name": "__MSG_appName__",
"version": "0.3.1"
"version": "0.3.2"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "115",
"version": "0.3.1",
"version": "0.3.2",
"description": "Assistant for 115 to export download links to aria2-rpc.",
"main": "background.js",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions src/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Home extends Downloader {
UI.addContextMenuRPCSectionWithCallback(() => {
this.addContextMenuEventListener()
})
Core.requestCookies([{ url: 'http://115.com/', name: 'UID' }, { url: 'http://115.com/', name: 'CID' }, { url: 'http://115.com/', name: 'SEID' }])
Core.showToast('初始化成功!', 'inf')
this.mode = 'RPC'
this.rpcURL = 'http://localhost:6800/jsonrpc'
Expand Down Expand Up @@ -108,7 +107,11 @@ class Home extends Downloader {
fetch(`//webapi.115.com/files/download?pickcode=${file}`, options).then((response) => {
if (response.ok) {
response.json().then((data) => {
resolve(data)
const path = data.file_url.match(/.*115.com(\/.*\/)/)[1]
Core.requestCookies([{path}]).then((cookies) => {
data.cookies = cookies
resolve(data)
})
})
} else {
console.log(response)
Expand All @@ -127,10 +130,11 @@ class Home extends Downloader {
this.fileDownloadInfo.push({
name: files[item.pickcode].path + item.file_name,
link: item.file_url,
sha1: files[item.pickcode].sha1
sha1: files[item.pickcode].sha1,
cookies: item.cookies
})
resolve()
})
resolve()
})
})
}
Expand Down
8 changes: 7 additions & 1 deletion src/js/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ class Core {
}
// cookies format [{"url": "http://pan.baidu.com/", "name": "BDUSS"},{"url": "http://pcs.baidu.com/", "name": "pcsett"}]
requestCookies (cookies) {
this.sendToBackground('getCookies', cookies, (value) => { this.cookies = value })
return new Promise((resolve) => {
this.sendToBackground('getCookies', cookies, (value) => {
resolve(value)
})
})
}
aria2RPCMode (rpcPath, fileDownloadInfo) {
const {authStr, path, options} = this.parseURL(rpcPath)
fileDownloadInfo.forEach((file) => {
this.cookies = file.cookies
const rpcData = {
jsonrpc: '2.0',
method: 'aria2.addUri',
Expand Down Expand Up @@ -193,6 +198,7 @@ class Core {
const downloadLinkTxt = []
const prefixTxt = 'data:text/plain;charset=utf-8,'
fileDownloadInfo.forEach((file) => {
this.cookies = file.cookies
let aria2CmdLine = `aria2c -c -s10 -k1M -x16 --enable-rpc=false -o ${JSON.stringify(file.name)} ${this.getHeader('aria2Cmd')} ${JSON.stringify(file.link)}`
let aria2Line = [file.link, this.getHeader('aria2c'), ` out=${file.name}`].join('\n')
const sha1Check = this.getConfigData('sha1Check')
Expand Down
4 changes: 2 additions & 2 deletions src/js/lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Store from './store'

class UI {
constructor () {
this.version = '0.3.1'
this.updateDate = '2018/06/05'
this.version = '0.3.2'
this.updateDate = '2018/06/10'
this.context = document.querySelector('iframe[rel="wangpan"]').contentDocument
Store.on('updateView', (configData) => {
this.updateSetting(configData)
Expand Down
4 changes: 3 additions & 1 deletion src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ function add115JS () {
}
}

iframe.addEventListener('load', add115JS)
if (iframe) {
iframe.addEventListener('load', add115JS)
}

0 comments on commit 99f7acd

Please sign in to comment.