nca-ai-cms-astro-plugin 1.0.1 → 1.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nca-ai-cms-astro-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -6,10 +6,7 @@ import { getEnvVariable } from '../utils/envUtils';
6
6
  import { jsonResponse, jsonError } from './_utils';
7
7
 
8
8
  const GenerateContentSchema = z.object({
9
- url: z.string().url().optional(),
10
- keywords: z.string().min(1).optional(),
11
- }).refine((data) => data.url || data.keywords, {
12
- message: 'URL or keywords required',
9
+ input: z.string().min(1, 'Input is required'),
13
10
  });
14
11
 
15
12
  export const POST: APIRoute = async ({ request }) => {
@@ -19,14 +16,15 @@ export const POST: APIRoute = async ({ request }) => {
19
16
  if (!parsed.success) {
20
17
  return jsonError(parsed.error.errors[0]?.message ?? 'Invalid request', 400);
21
18
  }
22
- const { url, keywords } = parsed.data;
19
+ const { input } = parsed.data;
20
+ const isUrl = /^https?:\/\//.test(input);
23
21
 
24
22
  const apiKey = getEnvVariable('GOOGLE_GEMINI_API_KEY');
25
23
  const promptService = new PromptService();
26
24
  const generator = new ContentGenerator({ apiKey, promptService });
27
- const article = url
28
- ? await generator.generateFromUrl(url)
29
- : await generator.generateFromKeywords(keywords!);
25
+ const article = isUrl
26
+ ? await generator.generateFromUrl(input)
27
+ : await generator.generateFromKeywords(input);
30
28
 
31
29
  return jsonResponse({
32
30
  title: article.title,
@@ -5,7 +5,7 @@ import { getEnvVariable } from '../utils/envUtils';
5
5
  import { jsonResponse, jsonError } from './_utils';
6
6
 
7
7
  const GenerateImageSchema = z.object({
8
- title: z.string().min(1, 'Title is required'),
8
+ input: z.string().min(1, 'Input is required'),
9
9
  });
10
10
 
11
11
  export const POST: APIRoute = async ({ request }) => {
@@ -15,11 +15,11 @@ export const POST: APIRoute = async ({ request }) => {
15
15
  if (!parsed.success) {
16
16
  return jsonError(parsed.error.errors[0]?.message ?? 'Invalid request', 400);
17
17
  }
18
- const { title } = parsed.data;
18
+ const { input } = parsed.data;
19
19
 
20
20
  const apiKey = getEnvVariable('GOOGLE_GEMINI_API_KEY');
21
21
  const generator = new ImageGenerator({ apiKey });
22
- const image = await generator.generate(title);
22
+ const image = await generator.generate(input);
23
23
 
24
24
  return jsonResponse({
25
25
  url: image.url,