forked from zhaohongxuan/obsidian-weread-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db20a94
commit 07a1af6
Showing
13 changed files
with
521 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "none", | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"overrides": [ | ||
{ | ||
"files": "*.ts", | ||
"options": { | ||
"parser": "typescript" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,61 @@ | ||
|
||
import { Notice } from 'obsidian'; | ||
import axios from 'axios'; | ||
export default class ApiManager { | ||
//will proxy to 'https://i.weread.qq.com'; | ||
readonly baseUrl: string = 'http://localhost:8081'; | ||
|
||
private getHeaders() { | ||
return { | ||
'Host': 'i.weread.qq.com', | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', | ||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', | ||
// 'Accept-Encoding': 'gzip, deflate, br', | ||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', | ||
'Content-Type': 'application/json', | ||
} | ||
} | ||
//will proxy to 'https://i.weread.qq.com'; | ||
readonly baseUrl: string = 'http://localhost:8081'; | ||
|
||
async getNotebooks() { | ||
try { | ||
let noteBooks =[] | ||
const resp = await axios.get(this.baseUrl+'/user/notebooks',{ | ||
}) | ||
private getHeaders() { | ||
return { | ||
Host: 'i.weread.qq.com', | ||
'User-Agent': | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', | ||
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', | ||
// 'Accept-Encoding': 'gzip, deflate, br', | ||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', | ||
'Content-Type': 'application/json' | ||
}; | ||
} | ||
|
||
noteBooks = resp.data.books | ||
//todo test code | ||
noteBooks = noteBooks.slice(0, 30) | ||
return noteBooks | ||
} catch (e) { | ||
new Notice('Failed to fetch weread notebooks . Please check your API token and try again.') | ||
} | ||
} | ||
async getNotebookHighlights(bookId:string) { | ||
async getNotebooks() { | ||
try { | ||
let noteBooks = []; | ||
const resp = await axios.get(this.baseUrl + '/user/notebooks', {}); | ||
|
||
try { | ||
const resp = await axios.get(this.baseUrl+'/book/bookmarklist?bookId='+bookId,{}) | ||
return resp.data | ||
} catch (e) { | ||
new Notice('Failed to fetch weread notebook highlights . Please check your API token and try again.') | ||
console.error(e); | ||
} | ||
} | ||
noteBooks = resp.data.books; | ||
//todo test code | ||
noteBooks = noteBooks.slice(0, 30); | ||
return noteBooks; | ||
} catch (e) { | ||
new Notice( | ||
'Failed to fetch weread notebooks . Please check your API token and try again.' | ||
); | ||
} | ||
} | ||
async getNotebookHighlights(bookId: string) { | ||
try { | ||
const resp = await axios.get( | ||
this.baseUrl + '/book/bookmarklist?bookId=' + bookId, | ||
{} | ||
); | ||
return resp.data; | ||
} catch (e) { | ||
new Notice( | ||
'Failed to fetch weread notebook highlights . Please check your API token and try again.' | ||
); | ||
console.error(e); | ||
} | ||
} | ||
|
||
async getNotebookReviews(bookId:string){ | ||
try { | ||
const requestUrl = `${this.baseUrl}/review/list?bookId=${bookId}&listType=11&mine=1&synckey=0` | ||
const resp = await axios.get(requestUrl) | ||
return resp.data | ||
} catch (e) { | ||
new Notice('Failed to fetch weread notebook reviews . Please check your API token and try again.') | ||
console.error(e); | ||
} | ||
} | ||
} | ||
async getNotebookReviews(bookId: string) { | ||
try { | ||
const requestUrl = `${this.baseUrl}/review/list?bookId=${bookId}&listType=11&mine=1&synckey=0`; | ||
const resp = await axios.get(requestUrl); | ||
return resp.data; | ||
} catch (e) { | ||
new Notice( | ||
'Failed to fetch weread notebook reviews . Please check your API token and try again.' | ||
); | ||
console.error(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.