dbm-graph-api 1.1.2 → 1.1.3
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/admin/edit/SetIdentifier.js +12 -0
- package/src/dbm-graph-api/admin/edit/index.js +9 -4
- package/src/dbm-graph-api/data/AltText.js +75 -0
- package/src/dbm-graph-api/data/SeoSummary.js +1 -0
- package/src/dbm-graph-api/data/UploadS3.js +14 -2
- package/src/dbm-graph-api/data/index.js +1 -0
- package/src/dbm-graph-api/index.js +8 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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.2",
|
|
17
17
|
"ws": "^8.18.0"
|
|
18
18
|
},
|
|
19
19
|
"optionalDependencies": {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class SetIdentifier extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.setIdentifier(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -2,11 +2,12 @@ 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";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
export const fullSetup = function() {
|
|
10
11
|
let prefix = "graphApi/admin/edit/";
|
|
11
12
|
{
|
|
12
13
|
let name = "setField";
|
|
@@ -14,6 +15,12 @@ let fullSetup = function() {
|
|
|
14
15
|
currentSelect.item.register(prefix + name);
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
{
|
|
19
|
+
let name = "setIdentifier";
|
|
20
|
+
let currentSelect = new DbmGraphApi.admin.edit.SetIdentifier();
|
|
21
|
+
currentSelect.item.register(prefix + name);
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
{
|
|
18
25
|
let name = "setUrl";
|
|
19
26
|
let currentSelect = new DbmGraphApi.admin.edit.SetUrl();
|
|
@@ -31,6 +38,4 @@ let fullSetup = function() {
|
|
|
31
38
|
let currentSelect = new DbmGraphApi.admin.edit.AddOutgoingRelation();
|
|
32
39
|
currentSelect.item.register(prefix + name);
|
|
33
40
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export {fullSetup};
|
|
41
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
let returnObject = {};
|
|
10
|
+
|
|
11
|
+
let imageId = aData["id"];
|
|
12
|
+
|
|
13
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
14
|
+
let item = await database.createObject("private", ["aiGeneratedAltText"]);
|
|
15
|
+
|
|
16
|
+
returnObject["id"] = item.id;
|
|
17
|
+
returnObject["imageId"] = imageId;
|
|
18
|
+
|
|
19
|
+
let image = database.getObject(imageId);
|
|
20
|
+
let fields = await image.getFields();
|
|
21
|
+
|
|
22
|
+
let url = fields["resizeUrl"];
|
|
23
|
+
if(url) {
|
|
24
|
+
url = url.split("{scale}").join("width=1024,height=1024")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
returnObject["url"] = url;
|
|
28
|
+
|
|
29
|
+
let instructions = "Generate an alt text for the image. Respond with only a json object {altText: string}, no markdown.";
|
|
30
|
+
|
|
31
|
+
let body = {
|
|
32
|
+
"model": "gpt-4o",
|
|
33
|
+
"response_format": { "type": "json_object" },
|
|
34
|
+
"max_tokens": 300,
|
|
35
|
+
"messages": [
|
|
36
|
+
{"role":"system","content": instructions},
|
|
37
|
+
{
|
|
38
|
+
"role": "user",
|
|
39
|
+
"content": [
|
|
40
|
+
{
|
|
41
|
+
"type": "image_url",
|
|
42
|
+
"image_url": {
|
|
43
|
+
"url": url
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let headers = {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: headers,
|
|
59
|
+
body: JSON.stringify(body),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
let data = await response.json();
|
|
63
|
+
console.log(data);
|
|
64
|
+
await item.updateField("response", data);
|
|
65
|
+
|
|
66
|
+
let message = data.choices[0].message;
|
|
67
|
+
console.log(message.content);
|
|
68
|
+
let responseContent = JSON.parse(message.content);
|
|
69
|
+
console.log(responseContent);
|
|
70
|
+
|
|
71
|
+
returnObject["altText"] = responseContent["altText"];
|
|
72
|
+
|
|
73
|
+
return returnObject;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -26,6 +26,7 @@ export default class SeoSummary extends Dbm.core.BaseObject {
|
|
|
26
26
|
|
|
27
27
|
let body = {
|
|
28
28
|
"model": "gpt-4o-mini",
|
|
29
|
+
"response_format": { "type": "json_object" },
|
|
29
30
|
"messages": [
|
|
30
31
|
{"role":"system","content": instructions},
|
|
31
32
|
{"role": "user", "content": contentString}
|
|
@@ -20,7 +20,8 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
20
20
|
async getData(aData, aEncodeSession) {
|
|
21
21
|
let returnObject = {};
|
|
22
22
|
|
|
23
|
-
let
|
|
23
|
+
let originalFileName = aData["fileName"];
|
|
24
|
+
let fileName = originalFileName.toLowerCase();
|
|
24
25
|
let mimeType = aData["mimeType"];
|
|
25
26
|
|
|
26
27
|
fileName = fileName.replace(/[åäã]/gi, 'a');
|
|
@@ -46,7 +47,8 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
46
47
|
fullPath = fullPath.split("{date}").join(dateDay);
|
|
47
48
|
fullPath = fullPath.split("{generatedId}").join(generatedId);
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
51
|
+
let item = await database.createObject("public", ["image"]);
|
|
50
52
|
|
|
51
53
|
fileName = fullPath + fileName;
|
|
52
54
|
let acl = this.item.acl;
|
|
@@ -60,8 +62,18 @@ export default class UploadS3 extends Dbm.core.BaseObject {
|
|
|
60
62
|
|
|
61
63
|
let presignedUrl = await getSignedUrl(this.item.client, command, { expiresIn: 360 });
|
|
62
64
|
|
|
65
|
+
await item.setIdentifier(generatedId);
|
|
66
|
+
await item.updateField("name", originalFileName);
|
|
67
|
+
await item.updateField("path", fileName);
|
|
68
|
+
await item.updateField("originalFileName", originalFileName);
|
|
69
|
+
await item.updateField("url", this.item.publicPath + fileName);
|
|
70
|
+
await item.updateField("resizeUrl", this.item.publicResizePath + fileName);
|
|
71
|
+
|
|
72
|
+
returnObject["id"] = item.id;
|
|
63
73
|
returnObject["identifier"] = generatedId;
|
|
64
74
|
returnObject["url"] = presignedUrl;
|
|
75
|
+
returnObject["name"] = fileName;
|
|
76
|
+
returnObject["originalFileName"] = fileName;
|
|
65
77
|
returnObject["publicUrl"] = this.item.publicPath + fileName;
|
|
66
78
|
returnObject["publicResizeUrl"] = this.item.publicResizePath + fileName;
|
|
67
79
|
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};
|
|
@@ -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";
|