6d5eb15b1b
Expose authenticated /api/mindspace/v1/oa/drive APIs over each user's oa/ workspace and wire a MindSpace entry at /space/oa/drive. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { resolveMindSpaceUserPublishDir } from '../mindspace-runtime-config.mjs';
|
|
import { ensureUserZoneDirs, resolveZoneDir } from '../user-space.mjs';
|
|
import { OA_DRIVE_DEFAULTS } from './drive-defaults.mjs';
|
|
|
|
export function resolveUserOaDriveRoot(h5Root, userId) {
|
|
const user = typeof userId === 'object' && userId !== null ? userId : { id: userId };
|
|
const workspaceRoot = resolveMindSpaceUserPublishDir(h5Root, user);
|
|
ensureUserZoneDirs(workspaceRoot);
|
|
return resolveZoneDir(workspaceRoot, 'oa');
|
|
}
|
|
|
|
export function createDriveContext(h5Root, userId) {
|
|
const normalizedUserId = String(
|
|
typeof userId === 'object' && userId !== null ? userId.id : userId,
|
|
).trim();
|
|
const uploadDir = resolveUserOaDriveRoot(h5Root, normalizedUserId);
|
|
fs.mkdirSync(uploadDir, { recursive: true });
|
|
for (const dirName of [
|
|
OA_DRIVE_DEFAULTS.trashDirName,
|
|
OA_DRIVE_DEFAULTS.metaDirName,
|
|
OA_DRIVE_DEFAULTS.sessionDirName,
|
|
]) {
|
|
fs.mkdirSync(path.join(uploadDir, dirName), { recursive: true });
|
|
}
|
|
return {
|
|
userId: normalizedUserId,
|
|
uploadDir,
|
|
...OA_DRIVE_DEFAULTS,
|
|
};
|
|
}
|