42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
const { Client, Databases, ID, Permission, Role } = require('node-appwrite');
|
|
require('dotenv').config({ path: '.env.local' });
|
|
|
|
async function setupStreamState() {
|
|
console.log("Configuring Stream State collection...");
|
|
const client = new Client()
|
|
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
|
|
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID)
|
|
.setKey(process.env.APPWRITE_API_KEY);
|
|
|
|
const databases = new Databases(client);
|
|
const dbId = process.env.APPWRITE_DATABASE_ID;
|
|
|
|
try {
|
|
const collection = await databases.createCollection(
|
|
dbId,
|
|
'stream_state',
|
|
'Stream State',
|
|
[
|
|
Permission.read(Role.any()),
|
|
Permission.update(Role.any()), // Permitimos a cualquiera actualizar por ahora para la demo
|
|
Permission.create(Role.any()),
|
|
Permission.delete(Role.any()),
|
|
]
|
|
);
|
|
console.log("Collection 'stream_state' created.");
|
|
|
|
// Attributes
|
|
await databases.createStringAttribute(dbId, 'stream_state', 'active_overlays', 10000, false);
|
|
|
|
console.log("Attributes created.");
|
|
} catch (e) {
|
|
if (e.code === 409) {
|
|
console.log("Collection already exists.");
|
|
} else {
|
|
console.error("Error creating collection:", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
setupStreamState();
|