-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
13 changed files
with
231 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
SIYUAN_API_URL=... | ||
# some api need to pass token | ||
SIYUAN_AUTH_TOKEN=... | ||
# siyuan | ||
SIYUAN_API_URL= | ||
SIYUAN_AUTH_TOKEN= | ||
|
||
# cnblogs | ||
CNBLOGS_API_URL= | ||
CNBLOGS_USERNAME= | ||
CNBLOGS_PASSWORD= | ||
|
||
# jvue | ||
JVUE_API_URL= | ||
JVUE_USERNAME= | ||
JVUE_PASSWORD= | ||
|
||
# conf | ||
CONF_API_URL= | ||
CONF_USERNAME= | ||
CONF_PASSWORD= | ||
|
||
# conf rest api | ||
CONFLUENCE_REST_API_URL= | ||
CONFLUENCE_REST_USERNAME= | ||
CONFLUENCE_REST_PASSWORD= |
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,9 @@ | ||
export class Post { | ||
postid: string | ||
title: string | ||
|
||
constructor() { | ||
this.postid = "" | ||
this.title = "" | ||
} | ||
} |
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,8 +1,26 @@ | ||
/** | ||
* 思源笔记 | ||
*/ | ||
const API_TYPE_SIYUAN = "siyuan" | ||
/** | ||
* JVue | ||
*/ | ||
const API_TYPE_JVUE = "jvue" | ||
/** | ||
* Confluence | ||
*/ | ||
const API_TYPE_CONF = "conf" | ||
/** | ||
* Cnblogs | ||
*/ | ||
const API_TYPE_CNBLOGS = "cnblogs" | ||
|
||
/** | ||
* API类型常量定义 | ||
*/ | ||
export const API_TYPE_CONSTANTS = { | ||
API_TYPE_SIYUAN | ||
API_TYPE_SIYUAN, | ||
API_TYPE_JVUE, | ||
API_TYPE_CONF, | ||
API_TYPE_CNBLOGS | ||
} |
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,11 @@ | ||
# metaweblog-api | ||
|
||
## 依赖 | ||
|
||
```json | ||
{ | ||
"dependencies": { | ||
"metaweblog-api": "^1.2.0" | ||
} | ||
} | ||
``` |
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,18 @@ | ||
import {IApi} from "../api"; | ||
import {API_TYPE_CONSTANTS} from "../constants"; | ||
import {MetaWeblogApiAdaptor} from "./metaWeblogApiAdaptor"; | ||
import MetaWeblog from "metaweblog-api"; | ||
|
||
/** | ||
* 博客园的API适配器 | ||
*/ | ||
export class CnblogsApiAdaptor extends MetaWeblogApiAdaptor implements IApi { | ||
constructor() { | ||
super(); | ||
|
||
this.metaWeblog = new MetaWeblog(process.env.CNBLOGS_API_URL || ""); | ||
this.username = process.env.CNBLOGS_USERNAME || "" | ||
this.password = process.env.CNBLOGS_PASSWORD || "" | ||
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CNBLOGS | ||
} | ||
} |
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,19 @@ | ||
import {IApi} from "../api"; | ||
import {MetaWeblogApiAdaptor} from "./metaWeblogApiAdaptor"; | ||
import {API_TYPE_CONSTANTS} from "../constants"; | ||
import MetaWeblog from "metaweblog-api"; | ||
|
||
/** | ||
* Confluence的API适配器 | ||
*/ | ||
export class ConfApiAdaptor extends MetaWeblogApiAdaptor implements IApi { | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.metaWeblog = new MetaWeblog(process.env.CONF_API_URL || ""); | ||
this.username = process.env.CONF_USERNAME || "" | ||
this.password = process.env.CONF_PASSWORD || "" | ||
this.appkey = API_TYPE_CONSTANTS.API_TYPE_CONF | ||
} | ||
} |
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,18 @@ | ||
import {IApi} from "../api"; | ||
import {MetaWeblogApiAdaptor} from "./metaWeblogApiAdaptor"; | ||
import MetaWeblog from "metaweblog-api"; | ||
import {API_TYPE_CONSTANTS} from "../constants"; | ||
|
||
/** | ||
* JVue的API适配器 | ||
*/ | ||
export class JvueApiAdaptor extends MetaWeblogApiAdaptor implements IApi { | ||
constructor() { | ||
super(); | ||
|
||
this.metaWeblog = new MetaWeblog(process.env.JVUE_API_URL || ""); | ||
this.username = process.env.JVUE_USERNAME || "" | ||
this.password = process.env.JVUE_PASSWORD || "" | ||
this.appkey = API_TYPE_CONSTANTS.API_TYPE_JVUE | ||
} | ||
} |
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,39 @@ | ||
import {IApi} from "../api"; | ||
import {Post} from "../common/post"; | ||
|
||
/** | ||
* 博客园的API适配器 | ||
*/ | ||
export class MetaWeblogApiAdaptor implements IApi { | ||
protected metaWeblog: any | ||
protected username: string | ||
protected password: string | ||
protected appkey: string | ||
|
||
constructor() { | ||
this.metaWeblog = null; | ||
this.username = "" | ||
this.password = "" | ||
this.appkey = "" | ||
} | ||
|
||
/** | ||
* getRecentPosts | ||
* https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.getRecentPosts | ||
* @param numOfPosts | ||
*/ | ||
public async getRecentPosts(numOfPosts: number): Promise<Array<any>> { | ||
let result: Array<Post> = [] | ||
const cnblogsPosts = await this.metaWeblog.getRecentPosts(this.appkey, this.username, this.password, numOfPosts); | ||
for (let i = 0; i < cnblogsPosts.length; i++) { | ||
const cnblogsPost = cnblogsPosts[i] | ||
|
||
// 适配公共属性 | ||
let commonPost = new Post() | ||
commonPost.title = cnblogsPost.title | ||
result.push(commonPost) | ||
} | ||
|
||
return result; | ||
} | ||
} |
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
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