notes-to-strapi-export-article-ai 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "notes-to-strapi-export-article-ai",
3
3
  "name": "Strapi Exporter AI",
4
- "version": "1.0.28",
4
+ "version": "1.0.30",
5
5
  "minAppVersion": "1.5.0",
6
6
  "description": "Effortlessly export your notes to Strapi CMS with AI-powered handling and SEO optimization.",
7
7
  "author": "Cinquin Andy",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notes-to-strapi-export-article-ai",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Effortlessly export your Obsidian notes to Strapi CMS with AI-powered image handling and SEO optimization. Replace all the images in your notes by uploaded images in Strapi, and add SEO metadata to uploaded images.",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -256,24 +256,26 @@ export async function processMarkdownContent(
256
256
 
257
257
  new Notice('Article content generated successfully!')
258
258
  try {
259
- const response = await this.app.requestUrl({
260
- url: useAdditionalCallAPI
259
+ const response = await fetch(
260
+ useAdditionalCallAPI
261
261
  ? settings.additionalUrl
262
262
  : settings.strapiArticleCreateUrl,
263
- method: 'POST',
264
- headers: {
265
- 'Content-Type': 'application/json',
266
- Authorization: `Bearer ${settings.strapiApiToken}`,
267
- },
268
- body: JSON.stringify(articleContent),
269
- })
263
+ {
264
+ method: 'POST',
265
+ headers: {
266
+ 'Content-Type': 'application/json',
267
+ Authorization: `Bearer ${settings.strapiApiToken}`,
268
+ },
269
+ body: JSON.stringify(articleContent),
270
+ }
271
+ )
270
272
 
271
- if (response.status === 200) {
273
+ if (response.ok) {
272
274
  new Notice(
273
275
  'Check your API content now, the article is created & uploaded! 🎉'
274
276
  )
275
277
  } else {
276
- const errorData = await response.json
278
+ const errorData = await response.json()
277
279
  new Notice(
278
280
  `Failed to create article in Strapi. Error: ${errorData.error.message}`
279
281
  )
@@ -357,7 +359,12 @@ export async function getImageBlob(
357
359
  file.extension.match(/^(jpg|jpeg|png|gif|bmp|webp)$/i)
358
360
  )
359
361
  if (files.length > 0) {
360
- const file = files[0] as TFile
362
+ // check the TFILE type, and not cast it to TFILE
363
+ if (!(files[0] instanceof TFile)) {
364
+ return null
365
+ }
366
+ const file = files[0]
367
+
361
368
  const blob = await app.vault.readBinary(file)
362
369
  return {
363
370
  name: file.name,
@@ -391,7 +398,15 @@ export async function getGalleryImageBlobs(
391
398
  )
392
399
  return Promise.all(
393
400
  files.map(async file => {
394
- const blob = await app.vault.readBinary(file as TFile)
401
+ // check the TFILE type, and not cast it to TFILE
402
+ if (!(file instanceof TFile)) {
403
+ return {
404
+ name: '',
405
+ blob: new Blob(),
406
+ path: '',
407
+ }
408
+ }
409
+ const blob = await app.vault.readBinary(file)
395
410
  return {
396
411
  name: file.name,
397
412
  blob: new Blob([blob], { type: 'image/png' }),
@@ -1,4 +1,4 @@
1
- import { Notice } from 'obsidian'
1
+ import { Notice, requestUrl } from 'obsidian'
2
2
  import { StrapiExporterSettings } from '../types/settings'
3
3
  import { ImageBlob, ImageDescription } from '../types/image'
4
4
 
@@ -31,8 +31,7 @@ export async function uploadImagesToStrapi(
31
31
  )
32
32
 
33
33
  try {
34
- const response = await this.app.requestUrl({
35
- url: `${settings.strapiUrl}/api/upload`,
34
+ const response = await fetch(`${settings.strapiUrl}/api/upload`, {
36
35
  method: 'POST',
37
36
  headers: {
38
37
  Authorization: `Bearer ${settings.strapiApiToken}`,
@@ -40,15 +39,15 @@ export async function uploadImagesToStrapi(
40
39
  body: formData,
41
40
  })
42
41
 
43
- if (response.status === 200) {
44
- const data = await response.json
42
+ if (response.ok) {
43
+ const data = await response.json()
45
44
  uploadedImages[imageDescription.name] = {
46
45
  url: data[0].url,
47
46
  data: data[0],
48
47
  id: data[0].id,
49
48
  }
50
49
  } else {
51
- const errorData = await response.json
50
+ const errorData = await response.json()
52
51
  new Notice(
53
52
  `Failed to upload image: ${imageDescription.name}. Error: ${errorData.error.message}`
54
53
  )
@@ -95,8 +94,7 @@ export async function uploadGalleryImagesToStrapi(
95
94
  formData.append('files', imageBlob.blob, imageBlob.name)
96
95
 
97
96
  try {
98
- const response = await this.app.requestUrl({
99
- url: `${settings.strapiUrl}/api/upload`,
97
+ const response = await fetch(`${settings.strapiUrl}/api/upload`, {
100
98
  method: 'POST',
101
99
  headers: {
102
100
  Authorization: `Bearer ${settings.strapiApiToken}`,
@@ -104,15 +102,15 @@ export async function uploadGalleryImagesToStrapi(
104
102
  body: formData,
105
103
  })
106
104
 
107
- if (response.status === 200) {
108
- const data = await response.json
105
+ if (response.ok) {
106
+ const data = await response.json()
109
107
  uploadedImages[imageBlob.name] = {
110
108
  url: data[0].url,
111
109
  id: data[0].id,
112
110
  data: data[0],
113
111
  }
114
112
  } else {
115
- const errorData = await response.json
113
+ const errorData = await response.json()
116
114
  new Notice(
117
115
  `Failed to upload gallery image: ${imageBlob.name}. Error: ${errorData.error.message}`
118
116
  )
package/versions.json CHANGED
@@ -24,5 +24,7 @@
24
24
  "1.0.25": "1.5.0",
25
25
  "1.0.26": "1.5.0",
26
26
  "1.0.27": "1.5.0",
27
- "1.0.28": "1.5.0"
27
+ "1.0.28": "1.5.0",
28
+ "1.0.29": "1.5.0",
29
+ "1.0.30": "1.5.0"
28
30
  }