Updates
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { DATASQUIREL_LoggedInUser, UserType } from "../../../types";
|
||||
|
||||
type Param = {
|
||||
user?: DATASQUIREL_LoggedInUser | UserType;
|
||||
userId?: string | number | null;
|
||||
dbSlug?: string;
|
||||
};
|
||||
|
||||
export default function grabUserDbFullName({ dbSlug, user, userId }: Param) {
|
||||
const finalUserId = user?.id || userId;
|
||||
|
||||
if (!finalUserId || !dbSlug)
|
||||
throw new Error(
|
||||
`Couldn't grab full DB name. Missing parameters finalUserId || dbSlug`
|
||||
);
|
||||
|
||||
if (dbSlug.match(/[^a-zA-Z0-9-_]/)) {
|
||||
throw new Error(`Invalid Database slug`);
|
||||
}
|
||||
|
||||
return `datasquirel_user_${finalUserId}_${dbSlug}`;
|
||||
}
|
||||
@@ -8,6 +8,11 @@ type Param = {
|
||||
};
|
||||
export default function grabDirNames(param?: Param) {
|
||||
const appDir = param?.appDir || process.env.DSQL_APP_DIR;
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR || "/static";
|
||||
|
||||
const finalUserId = param?.user?.id || param?.userId;
|
||||
|
||||
const publicImagesDir = path.join(STATIC_ROOT, `images`);
|
||||
|
||||
if (!appDir)
|
||||
throw new Error("Please provide the `DSQL_APP_DIR` env variable.");
|
||||
@@ -32,11 +37,15 @@ export default function grabDirNames(param?: Param) {
|
||||
);
|
||||
|
||||
const usersSchemaDir = path.join(schemasDir, `users`);
|
||||
const targetUserSchemaDir = finalUserId
|
||||
? path.join(usersSchemaDir, `user-${finalUserId}`)
|
||||
: undefined;
|
||||
const userTempSQLFilePath = targetUserSchemaDir
|
||||
? path.join(targetUserSchemaDir, `tmp.sql`)
|
||||
: undefined;
|
||||
|
||||
const userDirPath = param?.user?.id
|
||||
? path.join(usersSchemaDir, `user-${param.user.id}`)
|
||||
: param?.userId
|
||||
? path.join(usersSchemaDir, `user-${param.userId}`)
|
||||
const userDirPath = finalUserId
|
||||
? path.join(usersSchemaDir, `user-${finalUserId}`)
|
||||
: undefined;
|
||||
const userSchemaMainJSONFilePath = userDirPath
|
||||
? path.join(userDirPath, `main.json`)
|
||||
@@ -61,6 +70,10 @@ export default function grabDirNames(param?: Param) {
|
||||
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||
: undefined;
|
||||
|
||||
const userPublicMediaDir = finalUserId
|
||||
? path.join(publicImagesDir, `user-images/user-${finalUserId}`)
|
||||
: undefined;
|
||||
|
||||
const userPrivateDbImportZipFileName = `db-export.zip`;
|
||||
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
||||
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||
@@ -101,6 +114,7 @@ export default function grabDirNames(param?: Param) {
|
||||
tempDirName,
|
||||
defaultTableFieldsJSONFilePath,
|
||||
usersSchemaDir,
|
||||
targetUserSchemaDir,
|
||||
userSchemaMainJSONFilePath,
|
||||
userPrivateMediaDir,
|
||||
userPrivateExportsDir,
|
||||
@@ -121,5 +135,7 @@ export default function grabDirNames(param?: Param) {
|
||||
siteSetupFile,
|
||||
envFile,
|
||||
testEnvFile,
|
||||
userPublicMediaDir,
|
||||
userTempSQLFilePath,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user