Skip to content

Commit

Permalink
fic: declare a appUserDirectory for all user's files
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 18, 2024
1 parent c63262c commit 01407e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ interface DownloadModelResult {
}

export class ApplicationManager {
readonly homeDirectory: string; // todo: make configurable
readonly appUserDirectory: string; // todo: make configurable

constructor(
private git: GitManager,
private recipeStatusRegistry: RecipeStatusRegistry,
private extensionContext: ExtensionContext,
) {
this.homeDirectory = os.homedir();
this.appUserDirectory = path.join(os.homedir(), AI_STUDIO_FOLDER);
}

async pullApplication(recipe: Recipe, model: ModelInfo) {
// Create a TaskUtils object to help us
const taskUtil = new RecipeStatusUtils(recipe.id, this.recipeStatusRegistry);

const localFolder = path.join(this.homeDirectory, AI_STUDIO_FOLDER, recipe.id);
const localFolder = path.join(this.appUserDirectory, recipe.id);

// Adding checkout task
const checkoutTask: Task = {
Expand Down Expand Up @@ -218,7 +218,7 @@ export class ApplicationManager {
callback: (message: DownloadModelResult) => void,
destFileName?: string,
) {
const destDir = path.join(this.homeDirectory, AI_STUDIO_FOLDER, 'models', modelId);
const destDir = path.join(this.appUserDirectory, 'models', modelId);
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class ApplicationManager {
// todo: move somewhere else (dedicated to models)
getLocalModels(): LocalModelInfo[] {
const result: LocalModelInfo[] = [];
const modelsDir = path.join(this.homeDirectory, AI_STUDIO_FOLDER, 'models');
const modelsDir = path.join(this.appUserDirectory, 'models');
const entries = fs.readdirSync(modelsDir, { withFileTypes: true });
const dirs = entries.filter(dir => dir.isDirectory());
for (const d of dirs) {
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Category } from '@shared/src/models/ICategory';
import type { Recipe } from '@shared/src/models/IRecipe';
import content from './ai.json';
import type { ApplicationManager } from './managers/applicationManager';
import { AI_STUDIO_FOLDER } from './managers/applicationManager';
import type { RecipeStatusRegistry } from './registries/RecipeStatusRegistry';
import type { RecipeStatus } from '@shared/src/models/IRecipeStatus';
import type { ModelInfo } from '@shared/src/models/IModelInfo';
Expand Down Expand Up @@ -105,8 +104,7 @@ export class StudioApiImpl implements StudioAPI {
}

const modelPath = path.resolve(
this.applicationManager.homeDirectory,
AI_STUDIO_FOLDER,
this.applicationManager.appUserDirectory,
'models',
modelId,
localModelInfo[0].file,
Expand Down

0 comments on commit 01407e3

Please sign in to comment.