fix: build errors, missing deps, and restored server actions
This commit is contained in:
parent
bda5ab2c82
commit
8a6db9df86
23
package-lock.json
generated
23
package-lock.json
generated
@ -10,11 +10,13 @@
|
||||
"dependencies": {
|
||||
"appwrite": "^23.0.0",
|
||||
"axios": "^1.13.6",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.577.0",
|
||||
"next": "16.1.6",
|
||||
"node-appwrite": "^22.1.3",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
"react-dom": "19.2.3",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4.2.2",
|
||||
@ -2682,6 +2684,15 @@
|
||||
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/clsx": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
|
||||
"integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
@ -6276,6 +6287,16 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/tailwind-merge": {
|
||||
"version": "3.5.0",
|
||||
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.5.0.tgz",
|
||||
"integrity": "sha512-I8K9wewnVDkL1NTGoqWmVEIlUcB9gFriAEkXkfCjX5ib8ezGxtR3xD7iZIxrfArjEsH7F1CHD4RFUtxefdqV/A==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/dcastil"
|
||||
}
|
||||
},
|
||||
"node_modules/tailwindcss": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.2.2.tgz",
|
||||
|
||||
@ -11,11 +11,13 @@
|
||||
"dependencies": {
|
||||
"appwrite": "^23.0.0",
|
||||
"axios": "^1.13.6",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.577.0",
|
||||
"next": "16.1.6",
|
||||
"node-appwrite": "^22.1.3",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
"react-dom": "19.2.3",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4.2.2",
|
||||
|
||||
@ -1,32 +1,53 @@
|
||||
import { Client, Account, Databases, Storage } from 'appwrite';
|
||||
'use server'
|
||||
|
||||
import { Client, Databases, Storage, ID } from 'node-appwrite';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
||||
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
||||
const DATABASE_ID = 'main';
|
||||
|
||||
export const client = new Client();
|
||||
function getAdminClient() {
|
||||
return new Client()
|
||||
.setEndpoint(ENDPOINT)
|
||||
.setProject(PROJECT_ID)
|
||||
.setKey(process.env.APPWRITE_API_KEY || '');
|
||||
}
|
||||
|
||||
client
|
||||
.setEndpoint(ENDPOINT)
|
||||
.setProject(PROJECT_ID);
|
||||
export async function createDocumentServer(collectionId: string, data: any) {
|
||||
const client = getAdminClient();
|
||||
const databases = new Databases(client);
|
||||
const result = await databases.createDocument(DATABASE_ID, collectionId, ID.unique(), data);
|
||||
revalidatePath('/');
|
||||
return result;
|
||||
}
|
||||
|
||||
export const account = new Account(client);
|
||||
export const databases = new Databases(client);
|
||||
export const storage = new Storage(client);
|
||||
export async function updateDocumentServer(collectionId: string, documentId: string, data: any) {
|
||||
const client = getAdminClient();
|
||||
const databases = new Databases(client);
|
||||
const result = await databases.updateDocument(DATABASE_ID, collectionId, documentId, data);
|
||||
revalidatePath('/');
|
||||
return result;
|
||||
}
|
||||
|
||||
export const APPWRITE_ALMEIRA_CONFIG = {
|
||||
endpoint: ENDPOINT,
|
||||
projectId: PROJECT_ID,
|
||||
databaseId: 'main',
|
||||
collections: {
|
||||
posts: 'posts',
|
||||
media: 'media',
|
||||
events: 'events',
|
||||
classifieds: 'classifieds',
|
||||
entity: 'entity_config'
|
||||
},
|
||||
buckets: {
|
||||
media: 'media'
|
||||
}
|
||||
};
|
||||
export async function deleteDocumentServer(collectionId: string, documentId: string) {
|
||||
const client = getAdminClient();
|
||||
const databases = new Databases(client);
|
||||
const result = await databases.deleteDocument(DATABASE_ID, collectionId, documentId);
|
||||
revalidatePath('/');
|
||||
return result;
|
||||
}
|
||||
|
||||
export { ID } from 'appwrite';
|
||||
export async function uploadMediaServer(file: File) {
|
||||
const client = getAdminClient();
|
||||
const storage = new Storage(client);
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
// Nota: node-appwrite requiere un objeto con buffer y filename
|
||||
const result = await storage.createFile('media', ID.unique(), {
|
||||
buffer: buffer,
|
||||
filename: file.name,
|
||||
size: file.size,
|
||||
mimeType: file.type
|
||||
} as any);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use server'
|
||||
|
||||
import { Client, Databases, ID, Query } from 'node-appwrite';
|
||||
import { cookies } from 'next/headers';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
||||
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
||||
@ -31,28 +31,38 @@ export async function getEntityConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
// ALIAS PARA COMPATIBILIDAD CON DASHBOARD
|
||||
export const getEntity = getEntityConfig;
|
||||
|
||||
export async function updateEntityConfig(data: any) {
|
||||
try {
|
||||
const databases = await getAdminClient();
|
||||
const existing = await getEntityConfig();
|
||||
|
||||
if (existing) {
|
||||
return await databases.updateDocument(
|
||||
const result = await databases.updateDocument(
|
||||
DATABASE_ID,
|
||||
COLLECTION_ID,
|
||||
existing.$id,
|
||||
data
|
||||
);
|
||||
revalidatePath('/');
|
||||
return result;
|
||||
} else {
|
||||
return await databases.createDocument(
|
||||
const result = await databases.createDocument(
|
||||
DATABASE_ID,
|
||||
COLLECTION_ID,
|
||||
ID.unique(),
|
||||
data
|
||||
);
|
||||
revalidatePath('/');
|
||||
return result;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating entity config:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// ALIAS PARA COMPATIBILIDAD CON DASHBOARD
|
||||
export const updateEntity = updateEntityConfig;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user