@yrpri/api 9.0.117 → 9.0.119
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/app.js +4 -1
- package/authorization.cjs +4 -4
- package/controllers/index.cjs +3 -1
- package/models/post.cjs +1 -0
- package/package.json +2 -2
- package/services/llms/imageGeneration/chatGptImageGenerator.d.ts +1 -1
- package/services/llms/imageGeneration/chatGptImageGenerator.js +9 -6
- package/services/llms/imageGeneration/collectionImageGenerator.js +16 -5
package/app.js
CHANGED
|
@@ -507,10 +507,13 @@ export class YourPrioritiesApi {
|
|
|
507
507
|
this.app.set("views", __dirname + "/views");
|
|
508
508
|
this.app.set("view engine", "pug");
|
|
509
509
|
const store = new RedisStore({ client: this.redisClient, ttl: 86400 });
|
|
510
|
+
if (!process.env.SESSION_SECRET) {
|
|
511
|
+
throw new Error("SESSION_SECRET is not set");
|
|
512
|
+
}
|
|
510
513
|
const sessionConfig = {
|
|
511
514
|
store: store,
|
|
512
515
|
name: "yrpri.sid",
|
|
513
|
-
secret: process.env.SESSION_SECRET
|
|
516
|
+
secret: process.env.SESSION_SECRET,
|
|
514
517
|
resave: false,
|
|
515
518
|
proxy: process.env.USING_NGINX_PROXY ? true : undefined,
|
|
516
519
|
cookie: { autoSubDomain: true },
|
package/authorization.cjs
CHANGED
|
@@ -270,7 +270,7 @@ auth.authNeedsGroupAdminForCreate = function (group, req, done) {
|
|
|
270
270
|
done(null, false);
|
|
271
271
|
});
|
|
272
272
|
};
|
|
273
|
-
auth.
|
|
273
|
+
auth.authNeedsCommunityAdminForCreate = function (community, req, done) {
|
|
274
274
|
models.Community.findOne({
|
|
275
275
|
where: { id: community.id },
|
|
276
276
|
attributes: ["id", "access", "user_id", "configuration"],
|
|
@@ -1577,7 +1577,7 @@ auth.entity("category", function (req, done) {
|
|
|
1577
1577
|
// CREATE
|
|
1578
1578
|
// Create bulkStatusUpdate
|
|
1579
1579
|
auth.role("createCommunityBulkStatusUpdate.createBulkStatusUpdate", function (community, req, done) {
|
|
1580
|
-
auth.
|
|
1580
|
+
auth.authNeedsCommunityAdminForCreate(community, req, done);
|
|
1581
1581
|
});
|
|
1582
1582
|
auth.entity("createCommunityBulkStatusUpdate", function (req, done) {
|
|
1583
1583
|
var match = req.originalUrl.match(/bulk_status_updates\/(\w+)/);
|
|
@@ -1772,7 +1772,7 @@ auth.role("createDomainOrganization.createDomainOrganization", function (domain,
|
|
|
1772
1772
|
done(null, false);
|
|
1773
1773
|
});
|
|
1774
1774
|
});
|
|
1775
|
-
auth.role("createCommunityOrganization.createCommunityOrganization", function (
|
|
1775
|
+
auth.role("createCommunityOrganization.createCommunityOrganization", function (community, req, done) {
|
|
1776
1776
|
models.Community.findOne({
|
|
1777
1777
|
where: { id: community.id },
|
|
1778
1778
|
})
|
|
@@ -1780,7 +1780,7 @@ auth.role("createCommunityOrganization.createCommunityOrganization", function (d
|
|
|
1780
1780
|
if (!auth.isAuthenticated(req)) {
|
|
1781
1781
|
done(null, false);
|
|
1782
1782
|
}
|
|
1783
|
-
else if (community.access === models.
|
|
1783
|
+
else if (community.access === models.Community.ACCESS_PUBLIC) {
|
|
1784
1784
|
done(null, true);
|
|
1785
1785
|
}
|
|
1786
1786
|
else if (community.user_id === req.user.id) {
|
package/controllers/index.cjs
CHANGED
|
@@ -421,7 +421,9 @@ async function initializeIndexCache() {
|
|
|
421
421
|
log.error("Failed to initialize index cache", { error });
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
|
-
|
|
424
|
+
if (!process.env.SKIP_INDEX_HTML_CACHE) {
|
|
425
|
+
initializeIndexCache();
|
|
426
|
+
}
|
|
425
427
|
router.get("/", function (req, res) {
|
|
426
428
|
sendIndex(req, res);
|
|
427
429
|
});
|
package/models/post.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yrpri/api",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.119",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Bjarnason & Citizens Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@google-cloud/vertexai": "^1.10.0",
|
|
26
26
|
"@google-cloud/vision": "^5.1.0",
|
|
27
27
|
"@node-saml/passport-saml": "^5.0.1",
|
|
28
|
-
"@policysynth/agents": "^1.3.
|
|
28
|
+
"@policysynth/agents": "^1.3.99",
|
|
29
29
|
"async": "^3.2.6",
|
|
30
30
|
"authorized": "^1.0.0",
|
|
31
31
|
"aws-sdk": "^2.1692.0",
|
|
@@ -4,7 +4,7 @@ export declare class ChatGptImageGenerator implements IImageGenerator {
|
|
|
4
4
|
private readonly openAiKey?;
|
|
5
5
|
constructor(openAiKey?: string);
|
|
6
6
|
/**
|
|
7
|
-
* Generates an image URL from a prompt using OpenAI
|
|
7
|
+
* Generates an image URL from a prompt using OpenAI's gpt-image-1 model.
|
|
8
8
|
* The returned link remains live for ~60 minutes – be sure to download
|
|
9
9
|
* or cache it right away in the calling service.
|
|
10
10
|
*/
|
|
@@ -7,7 +7,7 @@ export class ChatGptImageGenerator {
|
|
|
7
7
|
this.openAiKey = openAiKey;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Generates an image URL from a prompt using OpenAI
|
|
10
|
+
* Generates an image URL from a prompt using OpenAI's gpt-image-1 model.
|
|
11
11
|
* The returned link remains live for ~60 minutes – be sure to download
|
|
12
12
|
* or cache it right away in the calling service.
|
|
13
13
|
*/
|
|
@@ -33,12 +33,15 @@ export class ChatGptImageGenerator {
|
|
|
33
33
|
prompt: finalPrompt,
|
|
34
34
|
quality: "medium",
|
|
35
35
|
n: 1,
|
|
36
|
-
size
|
|
36
|
+
size,
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
console.log("res", JSON.stringify(res, null, 2));
|
|
39
|
+
const b64Json = res?.data?.[0]?.b64_json;
|
|
40
|
+
if (b64Json) {
|
|
41
|
+
// Assuming the image is a PNG, adjust if another format is expected
|
|
42
|
+
return `data:image/png;base64,${b64Json}`;
|
|
43
|
+
}
|
|
44
|
+
throw new Error("No b64_json returned");
|
|
42
45
|
}
|
|
43
46
|
catch (err) {
|
|
44
47
|
retryCount += 1;
|
|
@@ -69,11 +69,22 @@ export class CollectionImageGenerator {
|
|
|
69
69
|
newImageUrl = imageUrl;
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
// 2) Download image to temporary location
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
// 2) Download image to temporary location or write data URI to file
|
|
73
|
+
if (imageUrl.startsWith("data:image")) {
|
|
74
|
+
const base64Data = imageUrl.split(",")[1];
|
|
75
|
+
if (!base64Data) {
|
|
76
|
+
return reject("Invalid data URI format.");
|
|
77
|
+
}
|
|
78
|
+
const imageBuffer = Buffer.from(base64Data, "base64");
|
|
79
|
+
fs.writeFileSync(imageFilePath, imageBuffer);
|
|
80
|
+
console.debug("Data URI written to file successfully.");
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await this.imageProcessorService.downloadImage(imageUrl, imageFilePath, axios);
|
|
84
|
+
console.debug(fs.existsSync(imageFilePath)
|
|
85
|
+
? "File downloaded successfully."
|
|
86
|
+
: "File download failed.");
|
|
87
|
+
}
|
|
77
88
|
// (Optional) If you want to resize the image before upload:
|
|
78
89
|
// const resizedPath = await this.imageProcessorService.resizeImage(imageFilePath, 1024, 1024);
|
|
79
90
|
// Upload the `resizedPath` instead of `imageFilePath`
|