Skip to content

fix: yuque new doc not display in TOC #1326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/common/backend/services/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ export interface ServiceMeta {
permission?: chrome.permissions.Permissions;
}

export interface UpdateTOCRequest {}

export interface DocumentService<T = any> {
getId(): string;

getRepositories(): Promise<Repository[]>;

createDocument(request: CreateDocumentRequest): Promise<CompleteStatus | void>;
createDocument(request: T): Promise<CompleteStatus | void>;

getUserInfo(): Promise<UserInfo>;

Expand Down
7 changes: 6 additions & 1 deletion src/common/backend/services/yuque/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompleteStatus, CreateDocumentRequest } from './../interface';
import { CompleteStatus, CreateDocumentRequest, UpdateTOCRequest } from './../interface';
import { Repository } from '../interface';

export enum RepositoryType {
Expand Down Expand Up @@ -53,3 +53,8 @@ export interface YuqueCompleteStatus extends CompleteStatus {
export interface YuqueCreateDocumentRequest extends CreateDocumentRequest {
slug?: string;
}

export interface YuqueUpdateTOCRequest extends UpdateTOCRequest{
repositoryId: string;
documentId: number[];
}
24 changes: 24 additions & 0 deletions src/common/backend/services/yuque/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
YuqueRepository,
YuqueCompleteStatus,
YuqueCreateDocumentRequest,
YuqueUpdateTOCRequest,
} from './interface';

const HOST = 'https://www.yuque.com';
Expand Down Expand Up @@ -100,6 +101,9 @@ export default class YuqueDocumentService implements DocumentService {
}
);
const data = response;

await this.updateYuqueTOC({ repositoryId, documentId: [data.id] });

return {
href: `${HOST}/${repository.namespace}/${data.slug}`,
repositoryId,
Expand Down Expand Up @@ -150,4 +154,24 @@ export default class YuqueDocumentService implements DocumentService {
return [];
}
};

private updateYuqueTOC = async (info: YuqueUpdateTOCRequest) => {
const { repositoryId, documentId } = info;
const requestBody = {
action: 'prependNode',
action_mode: 'child',
doc_ids: documentId,
type: 'DOC',
};

try {
const response = await this.request.put(`repos/${repositoryId}/toc`, {
data: requestBody,
});
return response;
} catch (_error) {
return {};
}

};
}
Loading