1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Doc: Auto-publish pre-release info to forum

This commit is contained in:
Laurent Cozic
2023-09-13 19:01:27 +01:00
parent cfc2a29df6
commit 1fd11588db
8 changed files with 159 additions and 4 deletions

View File

@@ -21,6 +21,11 @@ interface ForumTopPost {
title: string;
}
interface ForumTopic {
id: number;
topic_id: string;
}
export const config: ApiConfig = {
baseUrl: 'https://discourse.joplinapp.org',
key: '',
@@ -61,6 +66,7 @@ export const execApi = async (method: HttpMethod, path: string, body: Record<str
// Ignore - it just means that the error object is a plain string
}
(error as any).apiObject = apiObject;
(error as any).status = response.status;
throw error;
}
@@ -77,7 +83,34 @@ export const getForumTopPostByExternalId = async (externalId: string): Promise<F
raw: existingForumPost.raw,
};
} catch (error) {
if (error.status === 404) return null;
if (error.apiObject && error.apiObject.error_type === 'not_found') return null;
throw error;
}
};
export const getTopicByExternalId = async (externalId: string): Promise<ForumTopic> => {
try {
const existingForumTopic = await execApi(HttpMethod.GET, `t/external_id/${externalId}.json`);
return existingForumTopic;
} catch (error) {
if (error.status === 404) return null;
if (error.apiObject && error.apiObject.error_type === 'not_found') return null;
throw error;
}
};
export const createTopic = async (topic: any): Promise<ForumTopic> => {
return execApi(HttpMethod.POST, 'posts', topic);
};
export const createPost = async (topicId: number, post: any): Promise<ForumTopic> => {
return execApi(HttpMethod.POST, 'posts', {
topic_id: topicId,
...post,
});
};
export const updatePost = async (postId: number, content: any): Promise<void> => {
await execApi(HttpMethod.PUT, `posts/${postId}.json`, content);
};