1- import { DocumentService , CreateDocumentRequest } from '../../index' ;
1+ import { DocumentService } from '../../index' ;
22import { extend , RequestMethod } from 'umi-request' ;
3- import md5 from '@web-clipper/shared/lib/md5' ;
4- import { MemosBackendServiceConfig } from './interface' ;
53import { CompleteStatus } from '../interface' ;
64import { Repository } from '@/common/backend/services/interface' ;
5+ import {
6+ MemosBackendServiceConfig ,
7+ MemoCreateDocumentRequest ,
8+ MemosUserResponse ,
9+ MemosUserInfo
10+ } from './interface' ;
711
8- interface MemosUserResponse {
9- name : string ;
10- username : string ;
11- email : string ;
12- avatarUrl : string ;
13- description : string ;
14- }
15-
16- interface UserInfo {
17- name : string ;
18- avatar : string ;
19- homePage : string ;
20- description : string ;
21- }
2212
2313export default class MemosDocumentService implements DocumentService {
2414 private request : RequestMethod ;
2515 private token : string ;
2616 private origin : string ;
27- private userInfo : UserInfo | null ;
17+ private UserInfo : MemosUserInfo | null ;
2818
2919 constructor ( { accessToken, origin } : MemosBackendServiceConfig ) {
3020 const realHost = origin || 'https://demo.usememos.com' ;
@@ -54,17 +44,17 @@ export default class MemosDocumentService implements DocumentService {
5444 ) ;
5545 this . token = accessToken ;
5646 this . origin = realHost ;
57- this . userInfo = null ;
47+ this . UserInfo = null ;
5848 }
5949
6050 getId = ( ) => {
6151 return '0' ;
6252 } ;
6353
64- getUserInfo = async ( ) : Promise < UserInfo > => {
54+ getUserInfo = async ( ) : Promise < MemosUserInfo > => {
6555 const response = await this . request . post < MemosUserResponse > ( 'v1/auth/status' ) ;
6656
67- const userInfo : UserInfo = {
57+ const MemosUserInfo : MemosUserInfo = {
6858 name : response . username || 'Memos User' ,
6959 avatar : response . avatarUrl
7060 ? `${ this . origin } ${ response . avatarUrl } `
@@ -73,16 +63,25 @@ export default class MemosDocumentService implements DocumentService {
7363 description : response . description || 'Memos User' ,
7464 } ;
7565
76- this . userInfo = userInfo ;
77- return userInfo ;
66+ this . UserInfo = MemosUserInfo ;
67+ return MemosUserInfo ;
7868 } ;
7969
70+ private addTag = ( tags : string , content : string ) : string => {
71+ const tagArray = tags . split ( ',' ) . map ( tag => tag . trim ( ) ) . filter ( tag => tag ) ;
72+ const formattedTags = tagArray . map ( tag => `#${ tag } ` ) . join ( ' ' ) ;
73+ return `${ content } \n${ formattedTags } ` ;
74+ } ;
8075
8176 createDocument = async (
82- info : CreateDocumentRequest
77+ info : MemoCreateDocumentRequest
8378 ) : Promise < CompleteStatus > => {
84- if ( ! this . userInfo ) {
85- this . userInfo = await this . getUserInfo ( ) ;
79+ if ( ! this . UserInfo ) {
80+ this . UserInfo = await this . getUserInfo ( ) ;
81+ }
82+
83+ if ( info . tags ) {
84+ info . content = this . addTag ( info . tags , info . content ) ;
8685 }
8786
8887 const response = await this . request . post < {
@@ -92,12 +91,12 @@ export default class MemosDocumentService implements DocumentService {
9291 } > ( 'v1/memos' , {
9392 data : {
9493 content : info . content ,
95- visibility : 'PRIVATE' ,
94+ visibility : info . visibility || 'PRIVATE' ,
9695 } ,
9796 } ) ;
9897
9998 return {
100- href : `${ this . origin } /u/${ this . userInfo . name } ` ,
99+ href : `${ this . origin } /u/${ this . UserInfo . name } ` ,
101100 } ;
102101 } ;
103102
0 commit comments