dbm-graph-api 1.1.2 → 1.1.4
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/package.json +2 -2
- package/src/dbm-graph-api/UrlRequest.js +92 -0
- package/src/dbm-graph-api/WebSocketConnection.js +69 -30
- package/src/dbm-graph-api/admin/edit/ClearCloudflareCache.js +41 -0
- package/src/dbm-graph-api/admin/edit/{PurgeCache.js → SetIdentifier.js} +2 -3
- package/src/dbm-graph-api/admin/edit/index.js +15 -3
- package/src/dbm-graph-api/data/AltText.js +78 -0
- package/src/dbm-graph-api/data/FreeUrl.js +3 -0
- package/src/dbm-graph-api/data/SeoSummary.js +4 -0
- package/src/dbm-graph-api/data/UploadS3.js +17 -2
- package/src/dbm-graph-api/data/index.js +1 -0
- package/src/dbm-graph-api/index.js +41 -0
- package/src/dbm-graph-api/range/encode/EncodeBaseObject.js +8 -0
- package/src/dbm-graph-api/range/encode/Image.js +27 -0
- package/src/dbm-graph-api/range/encode/index.js +2 -1
- package/src/dbm-graph-api/range/select/IncludePrivate.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@aws-sdk/client-s3": "^3.741.0",
|
|
15
15
|
"@aws-sdk/s3-request-presigner": "^3.741.0",
|
|
16
|
-
"dbm": "^1.1.
|
|
16
|
+
"dbm": "^1.1.3",
|
|
17
17
|
"ws": "^8.18.0"
|
|
18
18
|
},
|
|
19
19
|
"optionalDependencies": {
|
|
@@ -8,6 +8,19 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
8
8
|
this._logs = [];
|
|
9
9
|
this._encodedObjects = [];
|
|
10
10
|
this._responseData = null;
|
|
11
|
+
|
|
12
|
+
this._request = null;
|
|
13
|
+
this._reply = null;
|
|
14
|
+
|
|
15
|
+
this.item.requireProperty("hasLoadedUser", false);
|
|
16
|
+
this.item.requireProperty("user", null);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setup(aRequest, aReply) {
|
|
20
|
+
this._request = aRequest;
|
|
21
|
+
this._reply = aReply;
|
|
22
|
+
|
|
23
|
+
return null;
|
|
11
24
|
}
|
|
12
25
|
|
|
13
26
|
async requestUrl(aUrl) {
|
|
@@ -98,6 +111,8 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
98
111
|
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
99
112
|
encodeSession.outputController = this;
|
|
100
113
|
|
|
114
|
+
//METODO: check visibility
|
|
115
|
+
|
|
101
116
|
await encodeSession.encodeSingleWithTypes(aId, aEncodes);
|
|
102
117
|
|
|
103
118
|
encodeSession.destroy();
|
|
@@ -132,6 +147,37 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
132
147
|
|
|
133
148
|
this._responseData = returnData;
|
|
134
149
|
}
|
|
150
|
+
|
|
151
|
+
async incomingWebhook(aWebhookType, aData) {
|
|
152
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
153
|
+
encodeSession.outputController = this;
|
|
154
|
+
|
|
155
|
+
let returnObject = {};
|
|
156
|
+
|
|
157
|
+
let type = aWebhookType;
|
|
158
|
+
let data = aData;
|
|
159
|
+
|
|
160
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
161
|
+
|
|
162
|
+
let webhookType = await database.getTypeObject("type/webhookType", type);
|
|
163
|
+
|
|
164
|
+
let incomingWebhook = await database.createObject("private", ["incomingWebhook"]);
|
|
165
|
+
await incomingWebhook.updateField("data", data);
|
|
166
|
+
await incomingWebhook.addIncomingRelation(webhookType, "for");
|
|
167
|
+
|
|
168
|
+
let actionType = await database.getTypeObject("type/actionType", "incomingWebhook/" + type);
|
|
169
|
+
let actionStatus = await database.getTypeObject("status/actionStatus", "readyToProcess");
|
|
170
|
+
|
|
171
|
+
let action = await database.createObject("private", ["action"]);
|
|
172
|
+
await action.addIncomingRelation(actionType, "for");
|
|
173
|
+
await action.addIncomingRelation(incomingWebhook, "from");
|
|
174
|
+
await action.addIncomingRelation(actionStatus, "for");
|
|
175
|
+
|
|
176
|
+
returnObject["id"] = incomingWebhook.id;
|
|
177
|
+
returnObject["action"] = action.id;
|
|
178
|
+
|
|
179
|
+
this._responseData = returnObject;
|
|
180
|
+
}
|
|
135
181
|
|
|
136
182
|
outputEncodedData(aId, aData, aEncoding) {
|
|
137
183
|
//console.log("UrlRequest::outputEncodedData");
|
|
@@ -143,4 +189,50 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
143
189
|
getResponse() {
|
|
144
190
|
return {"objects": this._encodedObjects, "data": this._responseData, "logs": this._logs};
|
|
145
191
|
}
|
|
192
|
+
|
|
193
|
+
async _loadUser() {
|
|
194
|
+
|
|
195
|
+
if(this._request.headers.cookie) {
|
|
196
|
+
let cookies = this._request.headers.cookie.split(";");
|
|
197
|
+
let currentArray = cookies;
|
|
198
|
+
let currentArrayLength = currentArray.length;
|
|
199
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
200
|
+
let [key, value] = currentArray[i].split("=");
|
|
201
|
+
if(key === "dbm_session" || key === " dbm_session") {
|
|
202
|
+
let userId = 1*value.split(":")[1];
|
|
203
|
+
let user = Dbm.getInstance().repository.getItem("graphDatabase").controller.getUser(userId);
|
|
204
|
+
|
|
205
|
+
let isValidSession = await user.verifySession(value);
|
|
206
|
+
|
|
207
|
+
if(isValidSession) {
|
|
208
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
209
|
+
|
|
210
|
+
let user = database.getUser(userId);
|
|
211
|
+
this.item.setValue("user", user);
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.item.setValue("hasLoadedUser", true);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async getUser() {
|
|
222
|
+
if(!this.item.hasLoadedUser) {
|
|
223
|
+
await this._loadUser();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this.item.user;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async requireRole(aRole) {
|
|
230
|
+
let user = await this.getUser();
|
|
231
|
+
|
|
232
|
+
if(!user) {
|
|
233
|
+
throw("Only signed in users can use this endpoint");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
146
238
|
}
|
|
@@ -6,6 +6,8 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
6
6
|
super._construct();
|
|
7
7
|
this._webSocket = null;
|
|
8
8
|
|
|
9
|
+
this.item.requireProperty("user", null);
|
|
10
|
+
|
|
9
11
|
this._callback_errorBound = this._callback_error.bind(this);
|
|
10
12
|
this._callback_messageBound = this._callback_message.bind(this);
|
|
11
13
|
this._callback_closeBound = this._callback_close.bind(this);
|
|
@@ -181,28 +183,39 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
181
183
|
break;
|
|
182
184
|
case "admin/createObject":
|
|
183
185
|
{
|
|
184
|
-
|
|
185
|
-
let
|
|
186
|
-
let
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
186
|
+
//METODO: require role
|
|
187
|
+
let returnId = 0;
|
|
188
|
+
let user = await this.getUser();
|
|
189
|
+
if(user) {
|
|
190
|
+
let types = data['types'];
|
|
191
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
192
|
+
let visibility = data['visibility'] ? data['visibility'] : 'draft';
|
|
193
|
+
|
|
194
|
+
let draftVisibility = await database.getVisibilityType(visibility);
|
|
195
|
+
|
|
196
|
+
let newObject = await database.createObject(draftVisibility, types);
|
|
197
|
+
|
|
198
|
+
if(data.changes) {
|
|
199
|
+
await this._applyChanges(newObject, data.changes, request);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if(data.encode) {
|
|
203
|
+
|
|
204
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
205
|
+
encodeSession.outputController = this;
|
|
206
|
+
|
|
207
|
+
await encodeSession.encodeSingleWithTypes(newObject.id, data.encode);
|
|
208
|
+
|
|
209
|
+
encodeSession.destroy();
|
|
210
|
+
}
|
|
191
211
|
|
|
192
|
-
|
|
193
|
-
await this._applyChanges(newObject, data.changes, request);
|
|
212
|
+
returnId = newObject.id;
|
|
194
213
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
199
|
-
encodeSession.outputController = this;
|
|
200
|
-
|
|
201
|
-
await encodeSession.encodeSingleWithTypes(newObject.id, data.encode);
|
|
202
|
-
|
|
203
|
-
encodeSession.destroy();
|
|
214
|
+
else {
|
|
215
|
+
//METODO: add logs
|
|
204
216
|
}
|
|
205
217
|
|
|
218
|
+
|
|
206
219
|
this._webSocket.send(JSON.stringify({"type": "item/response", "id": newObject.id, "requestId": data["requestId"]}));
|
|
207
220
|
}
|
|
208
221
|
break;
|
|
@@ -212,20 +225,27 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
212
225
|
|
|
213
226
|
let theObject = database.getObject(data.id);
|
|
214
227
|
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
let user = await this.getUser();
|
|
229
|
+
if(user) {
|
|
230
|
+
if(data.changes) {
|
|
231
|
+
await this._applyChanges(theObject, data.changes, request);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if(data.encode) {
|
|
235
|
+
|
|
236
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
237
|
+
encodeSession.outputController = this;
|
|
238
|
+
|
|
239
|
+
await encodeSession.encodeSingleWithTypes(theObject.id, data.encode);
|
|
240
|
+
|
|
241
|
+
encodeSession.destroy();
|
|
242
|
+
}
|
|
217
243
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
222
|
-
encodeSession.outputController = this;
|
|
223
|
-
|
|
224
|
-
await encodeSession.encodeSingleWithTypes(theObject.id, data.encode);
|
|
225
|
-
|
|
226
|
-
encodeSession.destroy();
|
|
244
|
+
else {
|
|
245
|
+
//METODO: add log
|
|
227
246
|
}
|
|
228
247
|
|
|
248
|
+
|
|
229
249
|
this._webSocket.send(JSON.stringify({"type": "item/response", "id": theObject.id, "requestId": data["requestId"]}));
|
|
230
250
|
}
|
|
231
251
|
break;
|
|
@@ -240,7 +260,9 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
240
260
|
let userId = 0;
|
|
241
261
|
if(isVerified) {
|
|
242
262
|
//METODO: set user for connection
|
|
263
|
+
|
|
243
264
|
userId = user.id;
|
|
265
|
+
this.item.setValue("user", user);
|
|
244
266
|
}
|
|
245
267
|
|
|
246
268
|
this._webSocket.send(JSON.stringify({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]}));
|
|
@@ -298,8 +320,25 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
298
320
|
|
|
299
321
|
setInitialUser(aId) {
|
|
300
322
|
|
|
301
|
-
|
|
323
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
324
|
+
|
|
325
|
+
let user = database.getUser(aId);
|
|
326
|
+
this.item.setValue("user", user);
|
|
302
327
|
|
|
303
328
|
this._webSocket.send(JSON.stringify({"type": "connectionReady", "user": aId}));
|
|
304
329
|
}
|
|
330
|
+
|
|
331
|
+
async getUser() {
|
|
332
|
+
return this.item.user;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async requireRole(aRole) {
|
|
336
|
+
let user = await this.getUser();
|
|
337
|
+
|
|
338
|
+
if(!user) {
|
|
339
|
+
throw("Only signed in users can use this endpoint");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
305
344
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class ClearCloudflareCache extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
|
|
11
|
+
let cloudflare = Dbm.getInstance().repository.getItem("cloudflare");
|
|
12
|
+
let url = await aObject.getUrl();
|
|
13
|
+
|
|
14
|
+
if(cloudflare.domain && cloudflare.zone) {
|
|
15
|
+
let fullUrl = cloudflare.domain + url;
|
|
16
|
+
|
|
17
|
+
let requestUrl = "https://api.cloudflare.com/client/v4/zones/" + cloudflare.zone + "/purge_cache";
|
|
18
|
+
|
|
19
|
+
let body = {
|
|
20
|
+
"files": [fullUrl]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let headers = {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
'Authorization': 'Bearer ' + cloudflare.cacheToken
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let response = await fetch(requestUrl, {
|
|
29
|
+
method: "DELETE",
|
|
30
|
+
headers: headers,
|
|
31
|
+
body: JSON.stringify(body),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let data = await response.json();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
//METODO: report error log
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import Dbm from "dbm";
|
|
2
2
|
import EditBaseObject from "./EditBaseObject.js";
|
|
3
3
|
|
|
4
|
-
export default class
|
|
4
|
+
export default class SetIdentifier extends EditBaseObject {
|
|
5
5
|
_construct() {
|
|
6
6
|
super._construct();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
async performChange(aObject, aData, aRequest) {
|
|
10
|
-
|
|
11
|
-
console.log(url);
|
|
10
|
+
await aObject.setIdentifier(aData["value"]);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
@@ -2,11 +2,13 @@ import DbmGraphApi from "../../../../index.js";
|
|
|
2
2
|
export {default as EditBaseObject} from "./EditBaseObject.js";
|
|
3
3
|
|
|
4
4
|
export {default as SetField} from "./SetField.js";
|
|
5
|
+
export {default as SetIdentifier} from "./SetIdentifier.js";
|
|
5
6
|
export {default as SetUrl} from "./SetUrl.js";
|
|
6
7
|
export {default as AddIncomingRelation} from "./AddIncomingRelation.js";
|
|
7
8
|
export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
|
|
9
|
+
export {default as ClearCloudflareCache} from "./ClearCloudflareCache.js";
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
export const fullSetup = function() {
|
|
10
12
|
let prefix = "graphApi/admin/edit/";
|
|
11
13
|
{
|
|
12
14
|
let name = "setField";
|
|
@@ -14,6 +16,12 @@ let fullSetup = function() {
|
|
|
14
16
|
currentSelect.item.register(prefix + name);
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
{
|
|
20
|
+
let name = "setIdentifier";
|
|
21
|
+
let currentSelect = new DbmGraphApi.admin.edit.SetIdentifier();
|
|
22
|
+
currentSelect.item.register(prefix + name);
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
{
|
|
18
26
|
let name = "setUrl";
|
|
19
27
|
let currentSelect = new DbmGraphApi.admin.edit.SetUrl();
|
|
@@ -31,6 +39,10 @@ let fullSetup = function() {
|
|
|
31
39
|
let currentSelect = new DbmGraphApi.admin.edit.AddOutgoingRelation();
|
|
32
40
|
currentSelect.item.register(prefix + name);
|
|
33
41
|
}
|
|
34
|
-
}
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
{
|
|
44
|
+
let name = "clearCache";
|
|
45
|
+
let currentSelect = new DbmGraphApi.admin.edit.ClearCloudflareCache();
|
|
46
|
+
currentSelect.item.register(prefix + name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class SeoSummary extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async getData(aData, aEncodeSession) {
|
|
9
|
+
|
|
10
|
+
await aEncodeSession.outputController.requireRole("admin");
|
|
11
|
+
|
|
12
|
+
let returnObject = {};
|
|
13
|
+
|
|
14
|
+
let imageId = aData["id"];
|
|
15
|
+
|
|
16
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
17
|
+
let item = await database.createObject("private", ["aiGeneratedAltText"]);
|
|
18
|
+
|
|
19
|
+
returnObject["id"] = item.id;
|
|
20
|
+
returnObject["imageId"] = imageId;
|
|
21
|
+
|
|
22
|
+
let image = database.getObject(imageId);
|
|
23
|
+
let fields = await image.getFields();
|
|
24
|
+
|
|
25
|
+
let url = fields["resizeUrl"];
|
|
26
|
+
if(url) {
|
|
27
|
+
url = url.split("{scale}").join("width=1024,height=1024")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
returnObject["url"] = url;
|
|
31
|
+
|
|
32
|
+
let instructions = "Generate an alt text for the image. Respond with only a json object {altText: string}, no markdown.";
|
|
33
|
+
|
|
34
|
+
let body = {
|
|
35
|
+
"model": "gpt-4o",
|
|
36
|
+
"response_format": { "type": "json_object" },
|
|
37
|
+
"max_tokens": 300,
|
|
38
|
+
"messages": [
|
|
39
|
+
{"role":"system","content": instructions},
|
|
40
|
+
{
|
|
41
|
+
"role": "user",
|
|
42
|
+
"content": [
|
|
43
|
+
{
|
|
44
|
+
"type": "image_url",
|
|
45
|
+
"image_url": {
|
|
46
|
+
"url": url
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let headers = {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: headers,
|
|
62
|
+
body: JSON.stringify(body),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let data = await response.json();
|
|
66
|
+
console.log(data);
|
|
67
|
+
await item.updateField("response", data);
|
|
68
|
+
|
|
69
|
+
let message = data.choices[0].message;
|
|
70
|
+
console.log(message.content);
|
|
71
|
+
let responseContent = JSON.parse(message.content);
|
|
72
|
+
console.log(responseContent);
|
|
73
|
+
|
|
74
|
+
returnObject["altText"] = responseContent["altText"];
|
|
75
|
+
|
|
76
|
+
return returnObject;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -6,6 +6,9 @@ export default class SeoSummary extends Dbm.core.BaseObject {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
async getData(aData, aEncodeSession) {
|
|
9
|
+
|
|
10
|
+
await aEncodeSession.outputController.requireRole("admin");
|
|
11
|
+
|
|
9
12
|
let returnObject = {};
|
|
10
13
|
|
|
11
14
|
let content = aData["value"];
|
|
@@ -26,6 +29,7 @@ export default class SeoSummary extends Dbm.core.BaseObject {
|
|
|
26
29
|
|
|
27
30
|
let body = {
|
|
28
31
|
"model": "gpt-4o-mini",
|
|
32
|
+
"response_format": { "type": "json_object" },
|
|
29
33
|
"messages": [
|
|
30
34
|
{"role":"system","content": instructions},
|
|
31
35
|
{"role": "user", "content": contentString}
|
|
@@ -18,9 +18,13 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async getData(aData, aEncodeSession) {
|
|
21
|
+
|
|
22
|
+
await aEncodeSession.outputController.requireRole("admin");
|
|
23
|
+
|
|
21
24
|
let returnObject = {};
|
|
22
25
|
|
|
23
|
-
let
|
|
26
|
+
let originalFileName = aData["fileName"];
|
|
27
|
+
let fileName = originalFileName.toLowerCase();
|
|
24
28
|
let mimeType = aData["mimeType"];
|
|
25
29
|
|
|
26
30
|
fileName = fileName.replace(/[åäã]/gi, 'a');
|
|
@@ -46,7 +50,8 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
46
50
|
fullPath = fullPath.split("{date}").join(dateDay);
|
|
47
51
|
fullPath = fullPath.split("{generatedId}").join(generatedId);
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
54
|
+
let item = await database.createObject("public", ["image"]);
|
|
50
55
|
|
|
51
56
|
fileName = fullPath + fileName;
|
|
52
57
|
let acl = this.item.acl;
|
|
@@ -60,8 +65,18 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
60
65
|
|
|
61
66
|
let presignedUrl = await getSignedUrl(this.item.client, command, { expiresIn: 360 });
|
|
62
67
|
|
|
68
|
+
await item.setIdentifier(generatedId);
|
|
69
|
+
await item.updateField("name", originalFileName);
|
|
70
|
+
await item.updateField("path", fileName);
|
|
71
|
+
await item.updateField("originalFileName", originalFileName);
|
|
72
|
+
await item.updateField("url", this.item.publicPath + fileName);
|
|
73
|
+
await item.updateField("resizeUrl", this.item.publicResizePath + fileName);
|
|
74
|
+
|
|
75
|
+
returnObject["id"] = item.id;
|
|
63
76
|
returnObject["identifier"] = generatedId;
|
|
64
77
|
returnObject["url"] = presignedUrl;
|
|
78
|
+
returnObject["name"] = fileName;
|
|
79
|
+
returnObject["originalFileName"] = fileName;
|
|
65
80
|
returnObject["publicUrl"] = this.item.publicPath + fileName;
|
|
66
81
|
returnObject["publicResizeUrl"] = this.item.publicResizePath + fileName;
|
|
67
82
|
returnObject["acl"] = acl;
|
|
@@ -2,6 +2,7 @@ export {default as Example} from "./Example.js";
|
|
|
2
2
|
export {default as UploadS3} from "./UploadS3.js";
|
|
3
3
|
export {default as FreeUrl} from "./FreeUrl.js";
|
|
4
4
|
export {default as SeoSummary} from "./SeoSummary.js";
|
|
5
|
+
export {default as AltText} from "./AltText.js";
|
|
5
6
|
|
|
6
7
|
import UploadS3 from "./UploadS3.js";
|
|
7
8
|
|
|
@@ -108,6 +108,13 @@ let fullEncodeSetup = function() {
|
|
|
108
108
|
currentEncode.item.register(encodePrefix + name);
|
|
109
109
|
currentEncode.item.setValue("encodingType", name);
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
let name = "image";
|
|
114
|
+
let currentEncode = new DbmGraphApi.range.encode.Image();
|
|
115
|
+
currentEncode.item.register(encodePrefix + name);
|
|
116
|
+
currentEncode.item.setValue("encodingType", name);
|
|
117
|
+
}
|
|
111
118
|
}
|
|
112
119
|
|
|
113
120
|
export {fullEncodeSetup};
|
|
@@ -124,6 +131,7 @@ let fullDataSetup = function() {
|
|
|
124
131
|
registerDataFunction("example", new DbmGraphApi.data.Example());
|
|
125
132
|
registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
|
|
126
133
|
registerDataFunction("admin/seoSummary", new DbmGraphApi.data.SeoSummary());
|
|
134
|
+
registerDataFunction("admin/altText", new DbmGraphApi.data.AltText());
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
export {fullDataSetup};
|
|
@@ -254,6 +262,7 @@ let setupEndpoints = function(aServer) {
|
|
|
254
262
|
console.log(url);
|
|
255
263
|
//METODO: check visibility in database
|
|
256
264
|
let request = new UrlRequest();
|
|
265
|
+
request.setup(aRequest, aReply);
|
|
257
266
|
|
|
258
267
|
await request.requestUrl(url);
|
|
259
268
|
|
|
@@ -276,6 +285,7 @@ let setupEndpoints = function(aServer) {
|
|
|
276
285
|
}
|
|
277
286
|
|
|
278
287
|
let request = new UrlRequest();
|
|
288
|
+
request.setup(aRequest, aReply);
|
|
279
289
|
|
|
280
290
|
await request.requestRange(selects, encodes, params);
|
|
281
291
|
|
|
@@ -288,6 +298,7 @@ let setupEndpoints = function(aServer) {
|
|
|
288
298
|
let encodes = aRequest.params.encodes.split(",");
|
|
289
299
|
|
|
290
300
|
let request = new UrlRequest();
|
|
301
|
+
request.setup(aRequest, aReply);
|
|
291
302
|
|
|
292
303
|
await request.requestItem(itemId, encodes);
|
|
293
304
|
|
|
@@ -297,6 +308,7 @@ let setupEndpoints = function(aServer) {
|
|
|
297
308
|
aServer.get('/api/data/*', async function handler (aRequest, aReply) {
|
|
298
309
|
let params = {...aRequest.query};
|
|
299
310
|
let request = new UrlRequest();
|
|
311
|
+
request.setup(aRequest, aReply);
|
|
300
312
|
|
|
301
313
|
let currentUrl = url.parse(aRequest.url);
|
|
302
314
|
let functionName = currentUrl.pathname.substring("/api/data/".length);
|
|
@@ -310,6 +322,7 @@ let setupEndpoints = function(aServer) {
|
|
|
310
322
|
|
|
311
323
|
let params = {...aRequest.query};
|
|
312
324
|
let request = new UrlRequest();
|
|
325
|
+
request.setup(aRequest, aReply);
|
|
313
326
|
|
|
314
327
|
let currentUrl = url.parse(aRequest.url);
|
|
315
328
|
let functionName = currentUrl.pathname.substring("/api/action/".length);
|
|
@@ -322,6 +335,7 @@ let setupEndpoints = function(aServer) {
|
|
|
322
335
|
aServer.post('/api/action/*', async function handler (aRequest, aReply) {
|
|
323
336
|
let params = {...aRequest.body};
|
|
324
337
|
let request = new UrlRequest();
|
|
338
|
+
request.setup(aRequest, aReply);
|
|
325
339
|
|
|
326
340
|
let currentUrl = url.parse(aRequest.url);
|
|
327
341
|
let functionName = currentUrl.pathname.substring("/api/action/".length);
|
|
@@ -333,6 +347,33 @@ let setupEndpoints = function(aServer) {
|
|
|
333
347
|
|
|
334
348
|
//METODO: setup raw data posts
|
|
335
349
|
|
|
350
|
+
aServer.get('/api/webhook/*', async function handler (aRequest, aReply) {
|
|
351
|
+
|
|
352
|
+
let params = {...aRequest.query};
|
|
353
|
+
let request = new UrlRequest();
|
|
354
|
+
request.setup(aRequest, aReply);
|
|
355
|
+
|
|
356
|
+
let currentUrl = url.parse(aRequest.url);
|
|
357
|
+
let webhookType = currentUrl.pathname.substring("/api/incomingWebhook/".length);
|
|
358
|
+
|
|
359
|
+
await request.incomingWebhook(webhookType, params);
|
|
360
|
+
|
|
361
|
+
return request.getResponse();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
aServer.post('/api/webhook/*', async function handler (aRequest, aReply) {
|
|
365
|
+
let params = {...aRequest.body};
|
|
366
|
+
let request = new UrlRequest();
|
|
367
|
+
request.setup(aRequest, aReply);
|
|
368
|
+
|
|
369
|
+
let currentUrl = url.parse(aRequest.url);
|
|
370
|
+
let webhookType = currentUrl.pathname.substring("/api/incomingWebhook/".length);
|
|
371
|
+
|
|
372
|
+
await request.incomingWebhook(webhookType, params);
|
|
373
|
+
|
|
374
|
+
return request.getResponse();
|
|
375
|
+
});
|
|
376
|
+
|
|
336
377
|
//METODO: setup edit
|
|
337
378
|
|
|
338
379
|
aServer.get('/api/', async function handler (aRequest, aResponse) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Image extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
14
|
+
|
|
15
|
+
let fields = await object.getFields();
|
|
16
|
+
returnObject["originalFileName"] = fields["originalFileName"];
|
|
17
|
+
returnObject["path"] = fields["path"];
|
|
18
|
+
returnObject["url"] = fields["url"];
|
|
19
|
+
returnObject["resizeUrl"] = fields["resizeUrl"];
|
|
20
|
+
returnObject["altText"] = this._dataOrNull(fields["altText"]);
|
|
21
|
+
|
|
22
|
+
await aEncodingSession.encodeSingle(aId, "identifier");
|
|
23
|
+
await aEncodingSession.encodeSingle(aId, "name");
|
|
24
|
+
|
|
25
|
+
return returnObject;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -9,4 +9,5 @@ export {default as UrlRequest} from "./UrlRequest.js";
|
|
|
9
9
|
export {default as Url} from "./Url.js";
|
|
10
10
|
export {default as Breadcrumb} from "./Breadcrumb.js";
|
|
11
11
|
export {default as NavigationName} from "./NavigationName.js";
|
|
12
|
-
export {default as Type} from "./Type.js";
|
|
12
|
+
export {default as Type} from "./Type.js";
|
|
13
|
+
export {default as Image} from "./Image.js";
|