- 
                Notifications
    
You must be signed in to change notification settings  - Fork 12
 
fix: ensure app dirs exist #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
- Ensure the WORKSPACE_DIR and SCRIPTS_PATH directories are created before attempting to use them. - Refactor misc related code Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
| const files = await fs.readdir(SCRIPTS_PATH()); | ||
| const gptFiles = files.filter(file => file.endsWith('.gpt')); | ||
| const scriptsPath = SCRIPTS_PATH() | ||
| await fs.mkdir(scriptsPath, {recursive: true}) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: fs.mkdir doesn't throw an error if the directory already exists when the recursive: true option is passed.
| export async function updateThread(id: string, thread: Thread) { | ||
| const threadsDir = THREADS_DIR(); | ||
| const threadPath = path.join(threadsDir,id); | ||
| 
               | 
          ||
| if (thread.state) await fs.writeFile(path.join(threadPath, STATE_FILE), thread.state); | ||
| if (thread.meta) { | ||
| const existingMeta = await fs.readFile(path.join(threadPath, META_FILE), "utf-8"); | ||
| const mergedMeta = { ...JSON.parse(existingMeta), ...thread.meta }; | ||
| await fs.writeFile(path.join(threadPath, META_FILE), JSON.stringify(mergedMeta)); | ||
| } | ||
| } No newline at end of file | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this isn't used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't right now.
| @@ -1,4 +1,6 @@ | |||
| 
               | 
          |||
| export const dynamic = 'force-dynamic' // defaults to autover' | |||
| import {NextResponse} from "next/server"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My linter was complaining about Response.json not existing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, it is auto imported I believe. Also this whole API section can get removed soonish. It isn't used right now, not important but just adjacent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Ensure the WORKSPACE_DIR and SCRIPTS_PATH directories are created before attempting to use them and refactor some misc related code.