diff --git a/package.json b/package.json index a82749e..be2796c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f283a48..8c37fb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ dependencies: '@lucia-auth/oauth': specifier: ^3.5.0 version: 3.5.0(lucia@2.7.6) + '@magitools/forem-wrapper': + specifier: ^0.0.1 + version: 0.0.1 bcryptjs: specifier: ^2.4.3 version: 2.4.3 @@ -1744,6 +1747,10 @@ packages: lucia: 2.7.6 dev: false + /@magitools/forem-wrapper@0.0.1: + resolution: {integrity: sha512-SDFdndyR8uaZAhOyx/CzlG7Hj9OXkJGZjvUusyhImqcm2ujI0QWt6oRG3oYhG2aZ/WmDQPnRl9e9hKRJVa2dRQ==} + dev: false + /@melt-ui/svelte@0.61.2(react@18.2.0)(svelte@4.2.8): resolution: {integrity: sha512-BHkD9G31zQBToA4euDRBgTQRvWxT9scufOVCXgDO6HKTvyxFspbWT2bgiSFqAK4BbAGDn9Ao36Q8F9O71KN4OQ==} peerDependencies: diff --git a/src/lib/articles/platforms/dev.ts b/src/lib/articles/platforms/dev.ts index ea2ca54..f9d51d4 100644 --- a/src/lib/articles/platforms/dev.ts +++ b/src/lib/articles/platforms/dev.ts @@ -1,3 +1,4 @@ +import ForemClient from '@magitools/forem-wrapper'; import { RegisterPlatform, type IBasePlatform, type IPlatformSetting } from './base'; @RegisterPlatform @@ -32,22 +33,13 @@ export class DevPlatform implements IBasePlatform { 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'); } }