octalens-mentions 0.0.12 → 0.0.13
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.
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const bootstrap = ({ strapi }) => {
|
|
3
|
+
};
|
|
4
|
+
const destroy = ({ strapi }) => {
|
|
5
|
+
};
|
|
6
|
+
const register = ({ strapi }) => {
|
|
7
|
+
};
|
|
8
|
+
const config = {
|
|
9
|
+
default: {},
|
|
10
|
+
validator() {
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const kind = "collectionType";
|
|
14
|
+
const collectionName = "mention";
|
|
15
|
+
const info = {
|
|
16
|
+
singularName: "mention",
|
|
17
|
+
pluralName: "mentions",
|
|
18
|
+
displayName: "Mention"
|
|
19
|
+
};
|
|
20
|
+
const options = {
|
|
21
|
+
draftAndPublish: false
|
|
22
|
+
};
|
|
23
|
+
const pluginOptions = {
|
|
24
|
+
"content-manager": {
|
|
25
|
+
visible: true
|
|
26
|
+
},
|
|
27
|
+
"content-type-builder": {
|
|
28
|
+
visible: false
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const attributes = {
|
|
32
|
+
action: {
|
|
33
|
+
type: "string"
|
|
34
|
+
},
|
|
35
|
+
title: {
|
|
36
|
+
type: "string"
|
|
37
|
+
},
|
|
38
|
+
body: {
|
|
39
|
+
type: "text"
|
|
40
|
+
},
|
|
41
|
+
url: {
|
|
42
|
+
type: "string"
|
|
43
|
+
},
|
|
44
|
+
timestamp: {
|
|
45
|
+
type: "string"
|
|
46
|
+
},
|
|
47
|
+
imageUrl: {
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
author: {
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
authorProfileLink: {
|
|
54
|
+
type: "string"
|
|
55
|
+
},
|
|
56
|
+
source: {
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
sourceId: {
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
relevanceScore: {
|
|
63
|
+
type: "string"
|
|
64
|
+
},
|
|
65
|
+
relevanceComment: {
|
|
66
|
+
type: "text"
|
|
67
|
+
},
|
|
68
|
+
keyword: {
|
|
69
|
+
type: "string"
|
|
70
|
+
},
|
|
71
|
+
bookmarked: {
|
|
72
|
+
type: "boolean",
|
|
73
|
+
"default": false
|
|
74
|
+
},
|
|
75
|
+
language: {
|
|
76
|
+
type: "string"
|
|
77
|
+
},
|
|
78
|
+
sentimentLabel: {
|
|
79
|
+
type: "string"
|
|
80
|
+
},
|
|
81
|
+
viewId: {
|
|
82
|
+
type: "integer"
|
|
83
|
+
},
|
|
84
|
+
viewName: {
|
|
85
|
+
type: "string"
|
|
86
|
+
},
|
|
87
|
+
subreddit: {
|
|
88
|
+
type: "string"
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const schema = {
|
|
92
|
+
kind,
|
|
93
|
+
collectionName,
|
|
94
|
+
info,
|
|
95
|
+
options,
|
|
96
|
+
pluginOptions,
|
|
97
|
+
attributes
|
|
98
|
+
};
|
|
99
|
+
const mention$2 = {
|
|
100
|
+
schema
|
|
101
|
+
};
|
|
102
|
+
const contentTypes = {
|
|
103
|
+
mention: mention$2
|
|
104
|
+
};
|
|
105
|
+
const { createCoreController } = require("@strapi/strapi").factories;
|
|
106
|
+
const mention$1 = createCoreController("plugin::octalens-mentions.mention");
|
|
107
|
+
function getMentionTitle(title, body) {
|
|
108
|
+
if (!title || title.trim() === "" || title.toLowerCase() === "untitled") {
|
|
109
|
+
if (!body) return "Untitled";
|
|
110
|
+
const excerpt = body.substring(0, 100).trim();
|
|
111
|
+
return excerpt.length === 100 ? `${excerpt}...` : excerpt;
|
|
112
|
+
}
|
|
113
|
+
return title;
|
|
114
|
+
}
|
|
115
|
+
const controller = ({ strapi }) => ({
|
|
116
|
+
async ingest(ctx) {
|
|
117
|
+
const requestBody = ctx.request.body;
|
|
118
|
+
if (!requestBody?.data) return ctx.badRequest("Missing data in request body");
|
|
119
|
+
const rawTitle = requestBody.data?.title || "";
|
|
120
|
+
const rawBody = requestBody.data?.body || "";
|
|
121
|
+
const generatedTitle = getMentionTitle(rawTitle, rawBody);
|
|
122
|
+
const mentionData = {
|
|
123
|
+
action: requestBody.action,
|
|
124
|
+
title: generatedTitle,
|
|
125
|
+
body: rawBody,
|
|
126
|
+
url: requestBody.data?.url || "",
|
|
127
|
+
timestamp: requestBody.data?.timestamp || "",
|
|
128
|
+
imageUrl: requestBody.data?.imageUrl || "",
|
|
129
|
+
author: requestBody.data?.author || "",
|
|
130
|
+
authorProfileLink: requestBody.data?.authorProfileLink || "",
|
|
131
|
+
source: requestBody.data?.source || "",
|
|
132
|
+
sourceId: requestBody.data?.sourceId || "",
|
|
133
|
+
relevanceScore: requestBody.data?.relevanceScore || "",
|
|
134
|
+
relevanceComment: requestBody.data?.relevanceComment || "",
|
|
135
|
+
keyword: requestBody.data?.keyword || "",
|
|
136
|
+
bookmarked: requestBody.data?.bookmarked || false,
|
|
137
|
+
language: requestBody.data?.language || "",
|
|
138
|
+
sentimentLabel: requestBody.data?.sentimentLabel || "",
|
|
139
|
+
viewId: requestBody.data?.viewId || null,
|
|
140
|
+
viewName: requestBody.data?.viewName || "",
|
|
141
|
+
subreddit: requestBody.data?.subreddit || ""
|
|
142
|
+
};
|
|
143
|
+
try {
|
|
144
|
+
const mention2 = await strapi.service("plugin::octalens-mentions.mention").create({
|
|
145
|
+
data: mentionData
|
|
146
|
+
});
|
|
147
|
+
ctx.body = { data: mention2 };
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Error creating mention:", error);
|
|
150
|
+
ctx.throw(500, "Failed to create mention");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const controllers = {
|
|
155
|
+
mention: mention$1,
|
|
156
|
+
ingest: controller
|
|
157
|
+
};
|
|
158
|
+
const middlewares = {};
|
|
159
|
+
const policies = {};
|
|
160
|
+
const adminApiRoutes = [
|
|
161
|
+
{
|
|
162
|
+
method: "GET",
|
|
163
|
+
path: "/mentions",
|
|
164
|
+
handler: "mention.find",
|
|
165
|
+
config: {
|
|
166
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
const contentApiRoutes = [
|
|
171
|
+
{
|
|
172
|
+
method: "GET",
|
|
173
|
+
path: "/mentions",
|
|
174
|
+
handler: "mention.find",
|
|
175
|
+
config: {
|
|
176
|
+
policies: []
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
method: "GET",
|
|
181
|
+
path: "/mentions/:id",
|
|
182
|
+
handler: "mention.findOne",
|
|
183
|
+
config: {
|
|
184
|
+
policies: []
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
method: "DELETE",
|
|
189
|
+
path: "/mentions/:id",
|
|
190
|
+
handler: "mention.delete",
|
|
191
|
+
config: {
|
|
192
|
+
policies: []
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
method: "PUT",
|
|
197
|
+
path: "/mentions/:id",
|
|
198
|
+
handler: "mention.update",
|
|
199
|
+
config: {
|
|
200
|
+
policies: []
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
method: "POST",
|
|
205
|
+
path: "/mentions",
|
|
206
|
+
handler: "mention.create",
|
|
207
|
+
config: {
|
|
208
|
+
policies: []
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
method: "POST",
|
|
213
|
+
path: "/ingest",
|
|
214
|
+
handler: "ingest.ingest"
|
|
215
|
+
}
|
|
216
|
+
];
|
|
217
|
+
const routes = {
|
|
218
|
+
"admin-api": {
|
|
219
|
+
type: "admin",
|
|
220
|
+
routes: [...adminApiRoutes]
|
|
221
|
+
},
|
|
222
|
+
"content-api": {
|
|
223
|
+
type: "content-api",
|
|
224
|
+
routes: [...contentApiRoutes]
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const { createCoreService } = require("@strapi/strapi").factories;
|
|
228
|
+
const mention = createCoreService("plugin::octalens-mentions.mention");
|
|
229
|
+
const services = {
|
|
230
|
+
mention
|
|
231
|
+
};
|
|
232
|
+
const index = {
|
|
233
|
+
register,
|
|
234
|
+
bootstrap,
|
|
235
|
+
destroy,
|
|
236
|
+
config,
|
|
237
|
+
controllers,
|
|
238
|
+
routes,
|
|
239
|
+
services,
|
|
240
|
+
contentTypes,
|
|
241
|
+
policies,
|
|
242
|
+
middlewares
|
|
243
|
+
};
|
|
244
|
+
module.exports = index;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
const bootstrap = ({ strapi }) => {
|
|
2
|
+
};
|
|
3
|
+
const destroy = ({ strapi }) => {
|
|
4
|
+
};
|
|
5
|
+
const register = ({ strapi }) => {
|
|
6
|
+
};
|
|
7
|
+
const config = {
|
|
8
|
+
default: {},
|
|
9
|
+
validator() {
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const kind = "collectionType";
|
|
13
|
+
const collectionName = "mention";
|
|
14
|
+
const info = {
|
|
15
|
+
singularName: "mention",
|
|
16
|
+
pluralName: "mentions",
|
|
17
|
+
displayName: "Mention"
|
|
18
|
+
};
|
|
19
|
+
const options = {
|
|
20
|
+
draftAndPublish: false
|
|
21
|
+
};
|
|
22
|
+
const pluginOptions = {
|
|
23
|
+
"content-manager": {
|
|
24
|
+
visible: true
|
|
25
|
+
},
|
|
26
|
+
"content-type-builder": {
|
|
27
|
+
visible: false
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const attributes = {
|
|
31
|
+
action: {
|
|
32
|
+
type: "string"
|
|
33
|
+
},
|
|
34
|
+
title: {
|
|
35
|
+
type: "string"
|
|
36
|
+
},
|
|
37
|
+
body: {
|
|
38
|
+
type: "text"
|
|
39
|
+
},
|
|
40
|
+
url: {
|
|
41
|
+
type: "string"
|
|
42
|
+
},
|
|
43
|
+
timestamp: {
|
|
44
|
+
type: "string"
|
|
45
|
+
},
|
|
46
|
+
imageUrl: {
|
|
47
|
+
type: "string"
|
|
48
|
+
},
|
|
49
|
+
author: {
|
|
50
|
+
type: "string"
|
|
51
|
+
},
|
|
52
|
+
authorProfileLink: {
|
|
53
|
+
type: "string"
|
|
54
|
+
},
|
|
55
|
+
source: {
|
|
56
|
+
type: "string"
|
|
57
|
+
},
|
|
58
|
+
sourceId: {
|
|
59
|
+
type: "string"
|
|
60
|
+
},
|
|
61
|
+
relevanceScore: {
|
|
62
|
+
type: "string"
|
|
63
|
+
},
|
|
64
|
+
relevanceComment: {
|
|
65
|
+
type: "text"
|
|
66
|
+
},
|
|
67
|
+
keyword: {
|
|
68
|
+
type: "string"
|
|
69
|
+
},
|
|
70
|
+
bookmarked: {
|
|
71
|
+
type: "boolean",
|
|
72
|
+
"default": false
|
|
73
|
+
},
|
|
74
|
+
language: {
|
|
75
|
+
type: "string"
|
|
76
|
+
},
|
|
77
|
+
sentimentLabel: {
|
|
78
|
+
type: "string"
|
|
79
|
+
},
|
|
80
|
+
viewId: {
|
|
81
|
+
type: "integer"
|
|
82
|
+
},
|
|
83
|
+
viewName: {
|
|
84
|
+
type: "string"
|
|
85
|
+
},
|
|
86
|
+
subreddit: {
|
|
87
|
+
type: "string"
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const schema = {
|
|
91
|
+
kind,
|
|
92
|
+
collectionName,
|
|
93
|
+
info,
|
|
94
|
+
options,
|
|
95
|
+
pluginOptions,
|
|
96
|
+
attributes
|
|
97
|
+
};
|
|
98
|
+
const mention$2 = {
|
|
99
|
+
schema
|
|
100
|
+
};
|
|
101
|
+
const contentTypes = {
|
|
102
|
+
mention: mention$2
|
|
103
|
+
};
|
|
104
|
+
const { createCoreController } = require("@strapi/strapi").factories;
|
|
105
|
+
const mention$1 = createCoreController("plugin::octalens-mentions.mention");
|
|
106
|
+
function getMentionTitle(title, body) {
|
|
107
|
+
if (!title || title.trim() === "" || title.toLowerCase() === "untitled") {
|
|
108
|
+
if (!body) return "Untitled";
|
|
109
|
+
const excerpt = body.substring(0, 100).trim();
|
|
110
|
+
return excerpt.length === 100 ? `${excerpt}...` : excerpt;
|
|
111
|
+
}
|
|
112
|
+
return title;
|
|
113
|
+
}
|
|
114
|
+
const controller = ({ strapi }) => ({
|
|
115
|
+
async ingest(ctx) {
|
|
116
|
+
const requestBody = ctx.request.body;
|
|
117
|
+
if (!requestBody?.data) return ctx.badRequest("Missing data in request body");
|
|
118
|
+
const rawTitle = requestBody.data?.title || "";
|
|
119
|
+
const rawBody = requestBody.data?.body || "";
|
|
120
|
+
const generatedTitle = getMentionTitle(rawTitle, rawBody);
|
|
121
|
+
const mentionData = {
|
|
122
|
+
action: requestBody.action,
|
|
123
|
+
title: generatedTitle,
|
|
124
|
+
body: rawBody,
|
|
125
|
+
url: requestBody.data?.url || "",
|
|
126
|
+
timestamp: requestBody.data?.timestamp || "",
|
|
127
|
+
imageUrl: requestBody.data?.imageUrl || "",
|
|
128
|
+
author: requestBody.data?.author || "",
|
|
129
|
+
authorProfileLink: requestBody.data?.authorProfileLink || "",
|
|
130
|
+
source: requestBody.data?.source || "",
|
|
131
|
+
sourceId: requestBody.data?.sourceId || "",
|
|
132
|
+
relevanceScore: requestBody.data?.relevanceScore || "",
|
|
133
|
+
relevanceComment: requestBody.data?.relevanceComment || "",
|
|
134
|
+
keyword: requestBody.data?.keyword || "",
|
|
135
|
+
bookmarked: requestBody.data?.bookmarked || false,
|
|
136
|
+
language: requestBody.data?.language || "",
|
|
137
|
+
sentimentLabel: requestBody.data?.sentimentLabel || "",
|
|
138
|
+
viewId: requestBody.data?.viewId || null,
|
|
139
|
+
viewName: requestBody.data?.viewName || "",
|
|
140
|
+
subreddit: requestBody.data?.subreddit || ""
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
const mention2 = await strapi.service("plugin::octalens-mentions.mention").create({
|
|
144
|
+
data: mentionData
|
|
145
|
+
});
|
|
146
|
+
ctx.body = { data: mention2 };
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.error("Error creating mention:", error);
|
|
149
|
+
ctx.throw(500, "Failed to create mention");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
const controllers = {
|
|
154
|
+
mention: mention$1,
|
|
155
|
+
ingest: controller
|
|
156
|
+
};
|
|
157
|
+
const middlewares = {};
|
|
158
|
+
const policies = {};
|
|
159
|
+
const adminApiRoutes = [
|
|
160
|
+
{
|
|
161
|
+
method: "GET",
|
|
162
|
+
path: "/mentions",
|
|
163
|
+
handler: "mention.find",
|
|
164
|
+
config: {
|
|
165
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
];
|
|
169
|
+
const contentApiRoutes = [
|
|
170
|
+
{
|
|
171
|
+
method: "GET",
|
|
172
|
+
path: "/mentions",
|
|
173
|
+
handler: "mention.find",
|
|
174
|
+
config: {
|
|
175
|
+
policies: []
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
method: "GET",
|
|
180
|
+
path: "/mentions/:id",
|
|
181
|
+
handler: "mention.findOne",
|
|
182
|
+
config: {
|
|
183
|
+
policies: []
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
method: "DELETE",
|
|
188
|
+
path: "/mentions/:id",
|
|
189
|
+
handler: "mention.delete",
|
|
190
|
+
config: {
|
|
191
|
+
policies: []
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
method: "PUT",
|
|
196
|
+
path: "/mentions/:id",
|
|
197
|
+
handler: "mention.update",
|
|
198
|
+
config: {
|
|
199
|
+
policies: []
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
method: "POST",
|
|
204
|
+
path: "/mentions",
|
|
205
|
+
handler: "mention.create",
|
|
206
|
+
config: {
|
|
207
|
+
policies: []
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
method: "POST",
|
|
212
|
+
path: "/ingest",
|
|
213
|
+
handler: "ingest.ingest"
|
|
214
|
+
}
|
|
215
|
+
];
|
|
216
|
+
const routes = {
|
|
217
|
+
"admin-api": {
|
|
218
|
+
type: "admin",
|
|
219
|
+
routes: [...adminApiRoutes]
|
|
220
|
+
},
|
|
221
|
+
"content-api": {
|
|
222
|
+
type: "content-api",
|
|
223
|
+
routes: [...contentApiRoutes]
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const { createCoreService } = require("@strapi/strapi").factories;
|
|
227
|
+
const mention = createCoreService("plugin::octalens-mentions.mention");
|
|
228
|
+
const services = {
|
|
229
|
+
mention
|
|
230
|
+
};
|
|
231
|
+
const index = {
|
|
232
|
+
register,
|
|
233
|
+
bootstrap,
|
|
234
|
+
destroy,
|
|
235
|
+
config,
|
|
236
|
+
controllers,
|
|
237
|
+
routes,
|
|
238
|
+
services,
|
|
239
|
+
contentTypes,
|
|
240
|
+
policies,
|
|
241
|
+
middlewares
|
|
242
|
+
};
|
|
243
|
+
export {
|
|
244
|
+
index as default
|
|
245
|
+
};
|
package/package.json
CHANGED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"kind": "collectionType",
|
|
3
|
-
"collectionName": "mention",
|
|
4
|
-
"info": {
|
|
5
|
-
"singularName": "mention",
|
|
6
|
-
"pluralName": "mentions",
|
|
7
|
-
"displayName": "Mention"
|
|
8
|
-
},
|
|
9
|
-
"options": {
|
|
10
|
-
"draftAndPublish": false
|
|
11
|
-
},
|
|
12
|
-
"pluginOptions": {
|
|
13
|
-
"content-manager": {
|
|
14
|
-
"visible": true
|
|
15
|
-
},
|
|
16
|
-
"content-type-builder": {
|
|
17
|
-
"visible": false
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"attributes": {
|
|
21
|
-
"action": {
|
|
22
|
-
"type": "string"
|
|
23
|
-
},
|
|
24
|
-
"title": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
},
|
|
27
|
-
"body": {
|
|
28
|
-
"type": "text"
|
|
29
|
-
},
|
|
30
|
-
"url": {
|
|
31
|
-
"type": "string"
|
|
32
|
-
},
|
|
33
|
-
"timestamp": {
|
|
34
|
-
"type": "string"
|
|
35
|
-
},
|
|
36
|
-
"imageUrl": {
|
|
37
|
-
"type": "string"
|
|
38
|
-
},
|
|
39
|
-
"author": {
|
|
40
|
-
"type": "string"
|
|
41
|
-
},
|
|
42
|
-
"authorProfileLink": {
|
|
43
|
-
"type": "string"
|
|
44
|
-
},
|
|
45
|
-
"source": {
|
|
46
|
-
"type": "string"
|
|
47
|
-
},
|
|
48
|
-
"sourceId": {
|
|
49
|
-
"type": "string"
|
|
50
|
-
},
|
|
51
|
-
"relevanceScore": {
|
|
52
|
-
"type": "string"
|
|
53
|
-
},
|
|
54
|
-
"relevanceComment": {
|
|
55
|
-
"type": "text"
|
|
56
|
-
},
|
|
57
|
-
"keyword": {
|
|
58
|
-
"type": "string"
|
|
59
|
-
},
|
|
60
|
-
"bookmarked": {
|
|
61
|
-
"type": "boolean",
|
|
62
|
-
"default": false
|
|
63
|
-
},
|
|
64
|
-
"language": {
|
|
65
|
-
"type": "string"
|
|
66
|
-
},
|
|
67
|
-
"sentimentLabel": {
|
|
68
|
-
"type": "string"
|
|
69
|
-
},
|
|
70
|
-
"viewId": {
|
|
71
|
-
"type": "integer"
|
|
72
|
-
},
|
|
73
|
-
"viewName": {
|
|
74
|
-
"type": "string"
|
|
75
|
-
},
|
|
76
|
-
"subreddit": {
|
|
77
|
-
"type": "string"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|