@rmdes/indiekit-endpoint-posts 1.0.0-beta.26 → 1.0.0-beta.28
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/lib/middleware/post-data.js +1 -5
- package/lib/utils.js +38 -17
- package/package.json +1 -1
|
@@ -51,11 +51,7 @@ export const postData = {
|
|
|
51
51
|
const { action, uid } = request.params;
|
|
52
52
|
const { access_token, scope } = request.session;
|
|
53
53
|
|
|
54
|
-
const properties = await getPostProperties(
|
|
55
|
-
uid,
|
|
56
|
-
application.micropubEndpoint,
|
|
57
|
-
access_token,
|
|
58
|
-
);
|
|
54
|
+
const properties = await getPostProperties(uid, application);
|
|
59
55
|
|
|
60
56
|
if (!properties) {
|
|
61
57
|
throw IndiekitError.notFound(response.locals.__("NotFoundError.page"));
|
package/lib/utils.js
CHANGED
|
@@ -147,25 +147,46 @@ export const getPostName = (publication, properties) => {
|
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* Query
|
|
151
|
-
* @param {string} uid -
|
|
152
|
-
* @param {
|
|
153
|
-
* @
|
|
154
|
-
* @returns {Promise<object>} JF2 properties
|
|
150
|
+
* Query database for post data by MongoDB _id
|
|
151
|
+
* @param {string} uid - MongoDB ObjectId string
|
|
152
|
+
* @param {object} application - Application object with collections
|
|
153
|
+
* @returns {Promise<object|false>} JF2 properties or false if not found
|
|
155
154
|
*/
|
|
156
|
-
export const getPostProperties = async (uid,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
155
|
+
export const getPostProperties = async (uid, application) => {
|
|
156
|
+
try {
|
|
157
|
+
const postsCollection = application?.collections?.get("posts");
|
|
158
|
+
if (!postsCollection) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Query using aggregation to match _id as string (avoids BSON version issues)
|
|
163
|
+
const results = await postsCollection
|
|
164
|
+
.aggregate([
|
|
165
|
+
{
|
|
166
|
+
$match: {
|
|
167
|
+
$expr: { $eq: [{ $toString: "$_id" }, uid] },
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
{ $limit: 1 },
|
|
171
|
+
])
|
|
172
|
+
.toArray();
|
|
173
|
+
|
|
174
|
+
const postData = results[0];
|
|
175
|
+
|
|
176
|
+
if (!postData?.properties) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Convert to JF2 format (properties already stored as JF2)
|
|
181
|
+
return {
|
|
182
|
+
...postData.properties,
|
|
183
|
+
uid: postData._id.toString(),
|
|
184
|
+
};
|
|
185
|
+
} catch (error) {
|
|
186
|
+
// Invalid ObjectId or database error
|
|
187
|
+
console.error("getPostProperties error:", error.message);
|
|
188
|
+
return false;
|
|
166
189
|
}
|
|
167
|
-
|
|
168
|
-
return false;
|
|
169
190
|
};
|
|
170
191
|
|
|
171
192
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-posts",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.28",
|
|
4
4
|
"description": "Post management endpoint for Indiekit with syndicate form fix. View posts published by your Micropub endpoint and publish new posts to it.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|