osuny-owl 1.0.0 → 1.0.1-alpha
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/index.js +86 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import 'dotenv/config'
|
|
2
2
|
|
|
3
|
+
import fetch from 'node-fetch'
|
|
4
|
+
|
|
3
5
|
export class OsunyOwl {
|
|
4
6
|
constructor(website_id, api_url){
|
|
5
7
|
this.website_id = website_id
|
|
6
8
|
this.category_ids = []
|
|
7
9
|
this.api_key_defined = process.env.OSUNY_API_KEY ? true : false
|
|
8
10
|
this.api_url = api_url
|
|
11
|
+
this.last_media = undefined
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
set website_id(website_id){
|
|
@@ -46,14 +49,6 @@ export class OsunyOwl {
|
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
/**
|
|
50
|
-
* TODO
|
|
51
|
-
*
|
|
52
|
-
* - function : postToOsuny(Communication::Post object)
|
|
53
|
-
* * Vérifier la connexion API
|
|
54
|
-
* * Vérifier qu'il y ait un site
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
52
|
|
|
58
53
|
/**
|
|
59
54
|
* Async function to post a Communication::Post object to a specific website
|
|
@@ -86,8 +81,37 @@ export class OsunyOwl {
|
|
|
86
81
|
}
|
|
87
82
|
} else {
|
|
88
83
|
throw new Error("No API Key Defined")
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async importImage(img_bdy){
|
|
88
|
+
|
|
89
|
+
if(this.api_key_defined){
|
|
90
|
+
const url = this.api_url + "/communication/medias"
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch(url, {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers:{
|
|
96
|
+
"X-Osuny-Token": process.env.OSUNY_API_KEY
|
|
97
|
+
},
|
|
98
|
+
body: img_bdy
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
if (!response.ok){
|
|
102
|
+
throw new Error(`Response status: ${response.status}, ${response.statusText}. Error: ${response.text()}`)
|
|
103
|
+
} else {
|
|
104
|
+
|
|
105
|
+
let dataR = await response.json()
|
|
106
|
+
this.last_media = dataR.original_blob
|
|
107
|
+
return true
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(error.message)
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
throw new Error("No API Key Defined")
|
|
89
114
|
}
|
|
90
|
-
|
|
91
115
|
}
|
|
92
116
|
}
|
|
93
117
|
|
|
@@ -181,6 +205,59 @@ export class OsunyUtility{
|
|
|
181
205
|
}
|
|
182
206
|
}
|
|
183
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Create a Video Block to include in an Osuny's Post
|
|
210
|
+
*
|
|
211
|
+
* @param {string} video_url (Required) The actual url of the video
|
|
212
|
+
* @param {string} migration_identifier (Required) A unique migration identifier
|
|
213
|
+
* @param {number} position (Required) Position of the block in the post
|
|
214
|
+
* @param {string} video_title Title of the video, will be displayed alongside the media
|
|
215
|
+
* @param {string} video_desc Description of the video, will be displayed as a paragraph alongside the media
|
|
216
|
+
* @param {string} video_transc (Recommended) Transcription of the video
|
|
217
|
+
* @param {string} title (Optional) Title of the block, will be displayed as h3 on the website
|
|
218
|
+
* @returns Osuny's Communication::Block (Video) object
|
|
219
|
+
*/
|
|
220
|
+
static createVideo(video_url, migration_identifier, position, video_title = "", video_desc = "", video_transc = "", title = ""){
|
|
221
|
+
return {
|
|
222
|
+
"id": null,
|
|
223
|
+
"migration_identifier": migration_identifier,
|
|
224
|
+
"template_kind": "video",
|
|
225
|
+
"title": title,
|
|
226
|
+
"position": position,
|
|
227
|
+
"published": "true",
|
|
228
|
+
"html_class": null,
|
|
229
|
+
"data": {
|
|
230
|
+
"layout": "player",
|
|
231
|
+
"description": video_desc,
|
|
232
|
+
"url": video_url,
|
|
233
|
+
"video_title": video_title,
|
|
234
|
+
"transcription": video_transc
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static createImage(img_id, img_filename, img_signedid, migration_identifier, position, alt="", credit="", text="", title = ""){
|
|
240
|
+
return {
|
|
241
|
+
"id": null,
|
|
242
|
+
"migration_identifier": migration_identifier,
|
|
243
|
+
"template_kind": "image",
|
|
244
|
+
"title": title,
|
|
245
|
+
"position": position,
|
|
246
|
+
"published": "true",
|
|
247
|
+
"html_class": null,
|
|
248
|
+
"data": {
|
|
249
|
+
"image": {
|
|
250
|
+
"id": img_id,
|
|
251
|
+
"filename": img_filename,
|
|
252
|
+
"signed_id": img_signedid
|
|
253
|
+
},
|
|
254
|
+
"alt": alt,
|
|
255
|
+
"credit": credit,
|
|
256
|
+
"text": text
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
184
261
|
/**
|
|
185
262
|
* Create a post Object to publish on a Osuny website
|
|
186
263
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osuny-owl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha",
|
|
4
4
|
"description": "Osuny Owl is an object that can go talk to the Osuny API, to create post or other osuny components from a large amount of data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"osuny",
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"dotenv": "^16.5.0",
|
|
18
|
-
"node-fetch": "^
|
|
18
|
+
"node-fetch": "^3.3.2"
|
|
19
19
|
}
|
|
20
20
|
}
|