mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-09-02 21:58:28 +00:00
Fix: Improve in-memory storage initialization by synchronizing creation of default data.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/ff560eae-8d69-4b22-9b4a-daa560012139.jpg
This commit is contained in:
+41
-6
@@ -172,14 +172,14 @@ export class MemStorage implements IStorage {
|
|||||||
credentials: { apiKey: process.env.CLOUDFLARE_API_KEY || "" },
|
credentials: { apiKey: process.env.CLOUDFLARE_API_KEY || "" },
|
||||||
isActive: true
|
isActive: true
|
||||||
};
|
};
|
||||||
this.createProvider(cloudflareProvider);
|
// Use synchronous creation to avoid promise issues
|
||||||
|
const provider = this.createProviderSync(cloudflareProvider);
|
||||||
|
|
||||||
// Create sample organization
|
// Create sample organization
|
||||||
const defaultOrg: InsertOrganization = {
|
const defaultOrg: InsertOrganization = {
|
||||||
name: "Default Organization",
|
name: "Default Organization",
|
||||||
isActive: true
|
isActive: true
|
||||||
};
|
};
|
||||||
const organization = this.createOrganization(defaultOrg);
|
|
||||||
|
|
||||||
// Create a sample admin user with fixed ID to properly reference it
|
// Create a sample admin user with fixed ID to properly reference it
|
||||||
let adminUser: User;
|
let adminUser: User;
|
||||||
@@ -187,6 +187,9 @@ export class MemStorage implements IStorage {
|
|||||||
if (existingAdmin) {
|
if (existingAdmin) {
|
||||||
adminUser = existingAdmin;
|
adminUser = existingAdmin;
|
||||||
} else {
|
} else {
|
||||||
|
// Create organization synchronously to get its ID directly
|
||||||
|
const org = this.createOrganizationSync(defaultOrg);
|
||||||
|
|
||||||
adminUser = {
|
adminUser = {
|
||||||
id: "1",
|
id: "1",
|
||||||
username: "admin",
|
username: "admin",
|
||||||
@@ -194,7 +197,7 @@ export class MemStorage implements IStorage {
|
|||||||
email: "admin@example.com",
|
email: "admin@example.com",
|
||||||
fullName: "System Admin",
|
fullName: "System Admin",
|
||||||
role: "admin",
|
role: "admin",
|
||||||
organizationId: organization.id,
|
organizationId: org.id,
|
||||||
createdAt: new Date()
|
createdAt: new Date()
|
||||||
};
|
};
|
||||||
this.usersMap.set(1, adminUser);
|
this.usersMap.set(1, adminUser);
|
||||||
@@ -288,6 +291,20 @@ export class MemStorage implements IStorage {
|
|||||||
return this.orgsMap.delete(parseInt(id));
|
return this.orgsMap.delete(parseInt(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Synchronous version of createOrganization for use in initialization
|
||||||
|
createOrganizationSync(org: InsertOrganization): Organization {
|
||||||
|
const numId = this.orgIdCounter++;
|
||||||
|
const createdAt = new Date();
|
||||||
|
const newOrg: Organization = {
|
||||||
|
id: numId.toString(),
|
||||||
|
name: org.name,
|
||||||
|
isActive: org.isActive ?? true,
|
||||||
|
createdAt
|
||||||
|
};
|
||||||
|
this.orgsMap.set(numId, newOrg);
|
||||||
|
return newOrg;
|
||||||
|
}
|
||||||
|
|
||||||
// Group management methods have been removed
|
// Group management methods have been removed
|
||||||
|
|
||||||
// Domains
|
// Domains
|
||||||
@@ -311,8 +328,8 @@ export class MemStorage implements IStorage {
|
|||||||
const newDomain: Domain = {
|
const newDomain: Domain = {
|
||||||
id: numId.toString(),
|
id: numId.toString(),
|
||||||
name: domain.name,
|
name: domain.name,
|
||||||
organizationId: domain.organizationId,
|
organizationId: domain.organizationId!,
|
||||||
providerId: domain.providerId,
|
providerId: domain.providerId || "1", // Default to the first provider if not specified
|
||||||
isActive: domain.isActive ?? true,
|
isActive: domain.isActive ?? true,
|
||||||
lastUpdated,
|
lastUpdated,
|
||||||
createdAt
|
createdAt
|
||||||
@@ -364,6 +381,8 @@ export class MemStorage implements IStorage {
|
|||||||
isActive: record.isActive ?? true,
|
isActive: record.isActive ?? true,
|
||||||
isAutoIP: record.isAutoIP ?? false,
|
isAutoIP: record.isAutoIP ?? false,
|
||||||
notes: record.notes ?? null,
|
notes: record.notes ?? null,
|
||||||
|
priority: record.priority ?? 0,
|
||||||
|
providerRecordId: record.providerRecordId ?? null,
|
||||||
lastUpdated,
|
lastUpdated,
|
||||||
createdAt
|
createdAt
|
||||||
};
|
};
|
||||||
@@ -427,6 +446,22 @@ export class MemStorage implements IStorage {
|
|||||||
return this.providersMap.delete(parseInt(id));
|
return this.providersMap.delete(parseInt(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Synchronous version of createProvider for use in initialization
|
||||||
|
createProviderSync(provider: InsertProvider): Provider {
|
||||||
|
const numId = this.providerIdCounter++;
|
||||||
|
const createdAt = new Date();
|
||||||
|
const newProvider: Provider = {
|
||||||
|
id: numId.toString(),
|
||||||
|
name: provider.name,
|
||||||
|
type: provider.type,
|
||||||
|
credentials: provider.credentials ?? null,
|
||||||
|
isActive: provider.isActive ?? true,
|
||||||
|
createdAt
|
||||||
|
};
|
||||||
|
this.providersMap.set(numId, newProvider);
|
||||||
|
return newProvider;
|
||||||
|
}
|
||||||
|
|
||||||
// API Tokens
|
// API Tokens
|
||||||
async getApiToken(id: string): Promise<ApiToken | undefined> {
|
async getApiToken(id: string): Promise<ApiToken | undefined> {
|
||||||
return this.apiTokensMap.get(parseInt(id));
|
return this.apiTokensMap.get(parseInt(id));
|
||||||
@@ -807,4 +842,4 @@ export class MemStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const storage = new DatabaseStorage();
|
export const storage = new MemStorage();
|
||||||
|
|||||||
Reference in New Issue
Block a user