Skip to content

Commit

Permalink
add: @magitools/forem-wrapper integration
Browse files Browse the repository at this point in the history
  • Loading branch information
matfire committed Jan 18, 2024
1 parent 59fb7ee commit 5166be7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@libsql/client": "^0.3.6",
"@lucia-auth/adapter-sqlite": "^2.0.1",
"@lucia-auth/oauth": "^3.5.0",
"@magitools/forem-wrapper": "^0.0.1",
"bcryptjs": "^2.4.3",
"bits-ui": "^0.13.2",
"clsx": "^2.1.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions src/lib/articles/platforms/dev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ForemClient from '@magitools/forem-wrapper';
import { RegisterPlatform, type IBasePlatform, type IPlatformSetting } from './base';

@RegisterPlatform
Expand Down Expand Up @@ -32,22 +33,13 @@ export class DevPlatform implements IBasePlatform<DevPlatform> {
public async publish(content: string) {
const setting = this.settings['api_token'];
if (!setting) throw new Error('could not find required settings');
const res = await fetch('https://dev.to/api/articles', {
method: 'post',
body: JSON.stringify({
article: {
title: this.frontmatter.title,
body_markdown: content,
published: this.frontmatter.published || false
}
}),
headers: {
accept: 'application/vnd.forem.api-v1+json',
'content-type': 'application/json',
'api-key': setting
}
});
if (!res.ok) {
try {
await new ForemClient().setApiKey(setting).article.publishArticle({
title: this.frontmatter.title,
body_markdown: content,
published: this.frontmatter.published || false
});
} catch (error) {
throw new Error('something went wrong');
}
}
Expand Down

0 comments on commit 5166be7

Please sign in to comment.