Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pagenote/pagenote
Browse files Browse the repository at this point in the history
  • Loading branch information
rowthan committed Nov 6, 2022
2 parents b8c8020 + 5503b87 commit eabe79b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 34 deletions.
3 changes: 1 addition & 2 deletions shared/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "@pagenote/shared",
"version": "1.7.7",
"version": "1.8.0",
"description": "",
"main": "lib/",
"dependencies": {
"axios": "^0.26.0",
"color": "^4.2.3",
"lodash": "^4.17.21",
"md5": "^2.3.0",
Expand Down
4 changes: 2 additions & 2 deletions shared/src/@types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ type Position = {
}

type PlainData = {

categories?: string[],
snapshots?: string[],
setting?: any,
Expand Down Expand Up @@ -116,6 +115,7 @@ type WebPageTimes = {
enum DataVersion {
version3='3', // 携带有 lastmode etag 字段
version4='4', // 删除 plainData 中网页信息字段
version5 = '5', // 迁移至 indexedDB
}

type WebPageSiteInfo = {
Expand All @@ -141,7 +141,7 @@ type RouteInfo = {
sessionId?: string
}

enum MetaResourceType {
export enum MetaResourceType {
image='image',
html='html',
}
Expand Down
2 changes: 0 additions & 2 deletions shared/src/@types/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export interface Find<Model> {
skip?: number, // 游标 TODO 删除,使用
next_cursor?: number | string,
projection?: Projection<Model>, // 字段过滤
// TODO 删除此字段
ignoreDetail?: boolean // 是否忽略详情,一般用于 list 列表时候,不需要查看详情
}

export interface FindResponse<T> {
Expand Down
20 changes: 14 additions & 6 deletions shared/src/extApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IBaseMessageListener,
IExtenstionMessageListener
} from "./communication/base";
import {AxiosRequestConfig, AxiosResponse} from "axios";
import {Action, ACTION_TYPES} from "./pagenote-actions/@types";
import {ConvertMethod, getDefaultConvertMethod} from "./pagenote-convert";
import {Brush, getDefaultBrush, LightStatus, LightType} from "./pagenote-brush";
Expand Down Expand Up @@ -199,7 +198,7 @@ export namespace setting {
export function getDefaultSdkSetting(originSetting: Partial<SDK_SETTING> = {}): SDK_SETTING {
const defaultBrushes = [
getDefaultBrush({
bg: '#FFFF83',
bg: '#ffe534',
}),
getDefaultBrush({
bg: '#A6FFE9',
Expand Down Expand Up @@ -449,10 +448,19 @@ export namespace fileDB {

export namespace network {
export const id = 'network';

export interface FetchRequest {
input: string,
init?: RequestInit & {data?: Record<string, any>}
}

export interface FetchResponse extends Response{
jsonData?: any
}

export interface response {
pagenote: IExtenstionMessageListener<AxiosRequestConfig, AxiosResponse>
axios: IExtenstionMessageListener<AxiosRequestConfig, AxiosResponse>
fetch: IExtenstionMessageListener<{input: string, init?: RequestInit}, Response & {jsonData?: any}>
pagenote: IExtenstionMessageListener<FetchRequest, FetchResponse>
fetch: IExtenstionMessageListener<FetchRequest, FetchResponse>
[key: string]: IExtenstionMessageListener<any, any>
}

Expand All @@ -473,7 +481,7 @@ export namespace frontApi {
makeHTMLSnapshot: IExtenstionMessageListener<void, { html: string, key: string }>
fetchStatus: IExtenstionMessageListener<void, { connected: boolean, active: boolean }>
// 通知刷新数据
refresh: IExtenstionMessageListener<void, void>
refresh: IExtenstionMessageListener<{ changes: {key?: string, url?: string, type?: 'page' | 'light' | string}[] }, void>
[key: string]: IExtenstionMessageListener<any, any>
}

Expand Down
4 changes: 2 additions & 2 deletions shared/src/pagenote-actions/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum ACTION_TYPES {
send_to_email = 'send_to_email',
search = 'search',
create_new_pagenote = 'create_new_pagenote',
axios='axios',
fetch='fetch',
}

export enum ACTION_SCENE {
Expand All @@ -38,4 +38,4 @@ export type Action = {
version: string,
actionType: ACTION_TYPES,
scene: ACTION_SCENE,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import {ACTION_SCENE, ACTION_TYPES} from "./@types";
import {PREDEFINED_ICON} from "../icons";

const version = '0.1.0'
const axios:ActionConfig = {
const fetch:ActionConfig = {
define:{
name:'请求 API',
actionType: ACTION_TYPES.axios,
actionType: ACTION_TYPES.fetch,
version: version,
icon: PREDEFINED_ICON.api,
clickScript: function (e,target,API,params,) {
const data = {
content: "#pagenote "+target.text,
}
API.methods.axios({
method: 'POST',
url: params.apiLink,
data: data
API.methods.fetch({
init:{
method: 'POST',
data: data
},
input: params.apiLink,
}).then(function(result){
API.methods.notification({
message: result.data.message
message: result.jsonData.message
})
console.log(result,'result')
}).catch(function(e){
Expand Down Expand Up @@ -57,4 +59,4 @@ const axios:ActionConfig = {
}
};

export default axios;
export default fetch;
11 changes: 6 additions & 5 deletions shared/src/pagenote-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import custom from "./custom";
import {Action, ACTION_SCENE, ACTION_TYPES} from "./@types";
import {ICON} from "../icons";
import {Target} from "../@types/data";
import axios from "./axios";
import {AxiosStatic} from "axios";

import fetch from "./fetch";
import { network} from "../extApi";
import FetchResponse = network.FetchResponse;
import FetchRequest = network.FetchRequest;
const defaultActionMap: Record<ACTION_TYPES,ActionConfig> = {
[ACTION_TYPES.custom]: custom,
[ACTION_TYPES.create_new_pagenote]: create_new_light,
[ACTION_TYPES.search]: search,
[ACTION_TYPES.send_to_email]: send_to_email,
[ACTION_TYPES.send_to_flomo]: send_to_flomo,
[ACTION_TYPES.copyToClipboard]: copy,
[ACTION_TYPES.axios]: axios,
[ACTION_TYPES.fetch]: fetch,
}

export const publicActionStores = [create_new_light,search,copy,send_to_email,send_to_flomo,custom]
Expand All @@ -35,7 +36,7 @@ export interface ActionAPI {
// toast提示
notification: (tip:{message: string,})=>void,
// 发送网络请求
axios: AxiosStatic,
fetch: (request: FetchRequest)=>Promise<FetchResponse>,
// 弹窗
popupwindow: (url:string, title:string, w?:number, h?:number)=>void,
// 弹窗对数据进行二次编辑数据
Expand Down
14 changes: 8 additions & 6 deletions shared/src/pagenote-actions/send_to_flomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ActionConfig} from "./index";
import {ACTION_SCENE, ACTION_TYPES} from "./@types";
import {PREDEFINED_ICON} from "../icons";

const version = '0.1.0'
const version = '0.2.0'
const send_to_flomo:ActionConfig = {
define:{
name:'Send to flomo',
Expand All @@ -15,13 +15,15 @@ const send_to_flomo:ActionConfig = {
const data = {
content: result,
}
API.methods.axios({
method: 'POST',
url: params.apiLink,
data: data
API.methods.fetch({
input: params.apiLink,
init:{
method: 'POST',
data: data
},
}).then(function(result){
API.methods.notification({
message: result.data.message
message: result.jsonData.message
})
console.log(result,'result')
}).catch(function(e){
Expand Down
2 changes: 1 addition & 1 deletion shared/src/pagenote-brush/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Brush {
}

export function getDefaultBrush(brush: Partial<Brush>={}):Brush {
let bg = brush.bg || '#FFDE5D';
let bg = brush.bg || 'rgba(19,77,222,0.5)';
let color = brush.color;
try{
if(bg.length <=6 && bg[0]!=='#'){
Expand Down

0 comments on commit eabe79b

Please sign in to comment.