fix: remove article API files to allow Strapi UI to recreate them
This commit is contained in:
parent
76963f6eea
commit
e443ece848
@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Lifecycle hooks for Article content type
|
||||
* Automatically notifies the backend when articles are published/updated/deleted
|
||||
*/
|
||||
|
||||
export default {
|
||||
async afterCreate(event) {
|
||||
const { result } = event;
|
||||
|
||||
// Only notify if article is published
|
||||
if (result.publishedAt) {
|
||||
await notifyBackend('entry.publish', result);
|
||||
}
|
||||
},
|
||||
|
||||
async afterUpdate(event) {
|
||||
const { result } = event;
|
||||
|
||||
if (result.publishedAt) {
|
||||
await notifyBackend('entry.update', result);
|
||||
} else {
|
||||
await notifyBackend('entry.unpublish', result);
|
||||
}
|
||||
},
|
||||
|
||||
async afterDelete(event) {
|
||||
const { result } = event;
|
||||
await notifyBackend('entry.delete', result);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Notify backend via webhook
|
||||
*/
|
||||
async function notifyBackend(event: string, entry: any) {
|
||||
const backendUrl = process.env.BACKEND_WEBHOOK_URL || 'http://backend:3000';
|
||||
const webhookUrl = `${backendUrl}/api/v1/webhooks/strapi/article`;
|
||||
|
||||
const payload = {
|
||||
event,
|
||||
model: 'article',
|
||||
entry: {
|
||||
documentId: entry.documentId,
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(webhookUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Webhook failed: ${response.status} ${response.statusText}`);
|
||||
} else {
|
||||
console.log(`✅ Webhook sent successfully: ${event} for article ${entry.documentId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to notify backend: ${error.message}`);
|
||||
}
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "articles",
|
||||
"info": {
|
||||
"singularName": "article",
|
||||
"pluralName": "articles",
|
||||
"displayName": "article"
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"content": {
|
||||
"type": "richtext"
|
||||
},
|
||||
"media": {
|
||||
"type": "media",
|
||||
"multiple": true,
|
||||
"allowedTypes": [
|
||||
"images",
|
||||
"files",
|
||||
"videos",
|
||||
"audios"
|
||||
]
|
||||
},
|
||||
"author": {
|
||||
"type": "string"
|
||||
},
|
||||
"img": {
|
||||
"type": "media",
|
||||
"multiple": false,
|
||||
"allowedTypes": [
|
||||
"images",
|
||||
"files",
|
||||
"videos",
|
||||
"audios"
|
||||
]
|
||||
},
|
||||
"imagePosition": {
|
||||
"type": "enumeration",
|
||||
"enum": ["top", "left", "right", "none"],
|
||||
"default": "top"
|
||||
},
|
||||
"imageSize": {
|
||||
"type": "enumeration",
|
||||
"enum": ["small", "medium", "large"],
|
||||
"default": "medium"
|
||||
},
|
||||
"videoUrl": {
|
||||
"type": "string",
|
||||
"regex": "^(https?:\\/\\/)?(www\\.)?(youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/)[a-zA-Z0-9_-]{11}",
|
||||
"default": ""
|
||||
},
|
||||
"videoPosition": {
|
||||
"type": "enumeration",
|
||||
"enum": ["top", "inline", "bottom", "none"],
|
||||
"default": "inline"
|
||||
},
|
||||
"videoCaption": {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
},
|
||||
"category": {
|
||||
"type": "enumeration",
|
||||
"enum": ["sport", "art", "science"],
|
||||
"default": "sport",
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
/**
|
||||
* article controller
|
||||
*/
|
||||
|
||||
import { factories } from '@strapi/strapi';
|
||||
|
||||
export default factories.createCoreController('api::article.article');
|
||||
@ -1,7 +0,0 @@
|
||||
/**
|
||||
* article router
|
||||
*/
|
||||
|
||||
import { factories } from '@strapi/strapi';
|
||||
|
||||
export default factories.createCoreRouter('api::article.article');
|
||||
@ -1,7 +0,0 @@
|
||||
/**
|
||||
* article service
|
||||
*/
|
||||
|
||||
import { factories } from '@strapi/strapi';
|
||||
|
||||
export default factories.createCoreService('api::article.article');
|
||||
Loading…
Reference in New Issue
Block a user