feat(dripzone): unify DripZone tables into almeira database and media_bucket on Appwrite Cloud
This commit is contained in:
parent
9a134b12ab
commit
3dc430e4e3
@ -1,7 +1,37 @@
|
|||||||
import { Client, Databases, Storage, Account } from 'appwrite';
|
import { Client, Databases, Storage, Account } from 'appwrite';
|
||||||
|
|
||||||
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
const origCall = (Client.prototype as any).call;
|
||||||
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
if (origCall && !(Client.prototype as any).__tablesDbPatched) {
|
||||||
|
(Client.prototype as any).__tablesDbPatched = true;
|
||||||
|
(Client.prototype as any).call = async function (method: string, url: URL, headers: Record<string, string> = {}, params: Record<string, any> = {}, responseType = 'json') {
|
||||||
|
let p = url.pathname;
|
||||||
|
if (p.includes('/databases/')) {
|
||||||
|
p = p
|
||||||
|
.replace('/databases/sneakers_multistore_db/', '/tablesdb/almeira/')
|
||||||
|
.replace('/databases/', '/tablesdb/')
|
||||||
|
.replace('/collections/cities', '/tables/dz_cities')
|
||||||
|
.replace('/collections/payment_methods', '/tables/dz_payment_methods')
|
||||||
|
.replace('/collections/', '/tables/')
|
||||||
|
.replace('/documents', '/rows')
|
||||||
|
.replace('/attributes', '/columns');
|
||||||
|
url = new URL(url.toString());
|
||||||
|
url.pathname = p;
|
||||||
|
} else if (p.includes('/buckets/sneakers_media_bucket')) {
|
||||||
|
p = p.replace('/buckets/sneakers_media_bucket', '/buckets/media_bucket');
|
||||||
|
url = new URL(url.toString());
|
||||||
|
url.pathname = p;
|
||||||
|
}
|
||||||
|
const res = await origCall.call(this, method, url, headers, params, responseType);
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
if (Array.isArray(res.rows) && !res.documents) res.documents = res.rows;
|
||||||
|
if (Array.isArray(res.tables) && !res.collections) res.collections = res.tables;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://nyc.cloud.appwrite.io/v1';
|
||||||
|
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '6aef63d9002c07371b40';
|
||||||
|
|
||||||
export const client = new Client();
|
export const client = new Client();
|
||||||
client.setEndpoint(endpoint).setProject(projectId);
|
client.setEndpoint(endpoint).setProject(projectId);
|
||||||
@ -10,17 +40,17 @@ export const databases = new Databases(client);
|
|||||||
export const storage = new Storage(client);
|
export const storage = new Storage(client);
|
||||||
export const account = new Account(client);
|
export const account = new Account(client);
|
||||||
|
|
||||||
// Base de datos y Bucket 100% aislados e independientes
|
// Unificado en la base de datos 'almeira' y bucket 'media_bucket' de Appwrite Cloud (Plan Gratuito)
|
||||||
export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID || 'sneakers_multistore_db';
|
export const DATABASE_ID = 'almeira';
|
||||||
export const BUCKET_ID = process.env.NEXT_PUBLIC_APPWRITE_MEDIA_BUCKET_ID || 'sneakers_media_bucket';
|
export const BUCKET_ID = 'media_bucket';
|
||||||
|
|
||||||
// Colecciones independientes
|
// Colecciones de DripZone dentro de la base de datos 'almeira'
|
||||||
export const COLLECTIONS = {
|
export const COLLECTIONS = {
|
||||||
PRODUCTS: 'products',
|
PRODUCTS: 'products',
|
||||||
CITIES: 'cities',
|
CITIES: 'dz_cities',
|
||||||
PAYMENT_METHODS: 'payment_methods',
|
PAYMENT_METHODS: 'dz_payment_methods',
|
||||||
ORDERS: 'orders',
|
ORDERS: 'orders',
|
||||||
SETTINGS: 'settings',
|
SETTINGS: 'store_settings',
|
||||||
SUPPLIER_POSTS: 'supplier_posts',
|
SUPPLIER_POSTS: 'supplier_posts',
|
||||||
CUSTOM_REQUESTS: 'custom_requests',
|
CUSTOM_REQUESTS: 'custom_requests',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -16,10 +16,48 @@ import { INITIAL_CITIES, INITIAL_PAYMENT_METHODS, INITIAL_SUPPLIERS, isGroupIgno
|
|||||||
import { DEFAULT_MESSAGE_TEMPLATES } from './templates-service';
|
import { DEFAULT_MESSAGE_TEMPLATES } from './templates-service';
|
||||||
import { sanitizePublicationTitle, sanitizePublicationText } from './sanitizer';
|
import { sanitizePublicationTitle, sanitizePublicationText } from './sanitizer';
|
||||||
|
|
||||||
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
const origCall = (Client.prototype as any).call;
|
||||||
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
if (origCall && !(Client.prototype as any).__tablesDbPatched) {
|
||||||
const apiKey = process.env.APPWRITE_API_KEY || 'standard_cce3cdb866ea6433888d40cedd24dc45987372308fdc3dd0697de08648c0e5c7e04b02c3bcee271403fd656b00a5820f04c08b51631284a6e8a3582d8aed2aa33234f3c29cc777e9b162eb54810b789251b0d006a9a3b081ebc2da53b9baa94614b124b3508ad849fd9a4187cc6094f506d4b57f409b69d9562a74df594f3ec3';
|
(Client.prototype as any).__tablesDbPatched = true;
|
||||||
const databaseId = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID || 'sneakers_multistore_db';
|
(Client.prototype as any).call = async function (method: string, url: URL, headers: Record<string, string> = {}, params: Record<string, any> = {}, responseType = 'json') {
|
||||||
|
let p = url.pathname;
|
||||||
|
if (p.includes('/databases/')) {
|
||||||
|
p = p
|
||||||
|
.replace('/databases/sneakers_multistore_db/', '/tablesdb/almeira/')
|
||||||
|
.replace('/databases/', '/tablesdb/')
|
||||||
|
.replace('/collections/cities', '/tables/dz_cities')
|
||||||
|
.replace('/collections/payment_methods', '/tables/dz_payment_methods')
|
||||||
|
.replace('/collections/', '/tables/')
|
||||||
|
.replace('/documents', '/rows')
|
||||||
|
.replace('/attributes', '/columns');
|
||||||
|
url = new URL(url.toString());
|
||||||
|
url.pathname = p;
|
||||||
|
if (params && typeof params === 'object' && !Array.isArray(params) && ('documentId' in params || 'data' in params)) {
|
||||||
|
const { documentId, data, permissions } = params;
|
||||||
|
params = {
|
||||||
|
...(documentId !== undefined ? { rowId: documentId } : {}),
|
||||||
|
...(data !== undefined ? { data } : {}),
|
||||||
|
...(permissions !== undefined ? { permissions } : {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (p.includes('/buckets/sneakers_media_bucket')) {
|
||||||
|
p = p.replace('/buckets/sneakers_media_bucket', '/buckets/media_bucket');
|
||||||
|
url = new URL(url.toString());
|
||||||
|
url.pathname = p;
|
||||||
|
}
|
||||||
|
const res = await origCall.call(this, method, url, headers, params, responseType);
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
if (Array.isArray(res.rows) && !res.documents) res.documents = res.rows;
|
||||||
|
if (Array.isArray(res.tables) && !res.collections) res.collections = res.tables;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://nyc.cloud.appwrite.io/v1';
|
||||||
|
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '6aef63d9002c07371b40';
|
||||||
|
const apiKey = process.env.APPWRITE_API_KEY || 'standard_79704037e869df69b7efcecdf51370360781c1b335d8a16148639c71382d8c9e94c4d49d27c2da0b8dde8e430084b895cc9756d8bb2cf927a4e96c59e3258d79d1119dac4167cee6b1e737a3444982e16187842cfffde1cc8c07c2f3c48d032ec1c164a802deacf6393bedd815b2868cf7faf374815aebe72777c4616d26db40';
|
||||||
|
const databaseId = 'almeira';
|
||||||
|
|
||||||
const client = new Client()
|
const client = new Client()
|
||||||
.setEndpoint(endpoint)
|
.setEndpoint(endpoint)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user