feat: Add Load Script functionality to script detail modal
- Create ScriptDownloaderService to download and modify script files from GitHub - Add tRPC routes for loading scripts and checking file existence - Add Load Script button to ScriptDetailModal with loading states - Implement sed replacement for build.func source line in CT scripts - Download CT scripts to scripts/ct/ and install scripts to scripts/install/ - Add visual indicators for script file availability - Show success/error messages for script loading operations
This commit is contained in:
@@ -4,6 +4,7 @@ import { scriptManager } from "~/server/lib/scripts";
|
||||
import { gitManager } from "~/server/lib/git";
|
||||
import { githubService } from "~/server/services/github";
|
||||
import { localScriptsService } from "~/server/services/localScripts";
|
||||
import { scriptDownloaderService } from "~/server/services/scriptDownloader";
|
||||
|
||||
export const scriptsRouter = createTRPCRouter({
|
||||
// Get all available scripts
|
||||
@@ -137,5 +138,66 @@ export const scriptsRouter = createTRPCRouter({
|
||||
count: 0
|
||||
};
|
||||
}
|
||||
}),
|
||||
|
||||
// Load script files from GitHub
|
||||
loadScript: publicProcedure
|
||||
.input(z.object({ slug: z.string() }))
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
// Get the script details
|
||||
const script = await localScriptsService.getScriptBySlug(input.slug);
|
||||
if (!script) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Script not found',
|
||||
files: []
|
||||
};
|
||||
}
|
||||
|
||||
// Load the script files
|
||||
const result = await scriptDownloaderService.loadScript(script);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('Error in loadScript:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to load script',
|
||||
files: []
|
||||
};
|
||||
}
|
||||
}),
|
||||
|
||||
// Check if script files exist locally
|
||||
checkScriptFiles: publicProcedure
|
||||
.input(z.object({ slug: z.string() }))
|
||||
.query(async ({ input }) => {
|
||||
try {
|
||||
const script = await localScriptsService.getScriptBySlug(input.slug);
|
||||
if (!script) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Script not found',
|
||||
ctExists: false,
|
||||
installExists: false,
|
||||
files: []
|
||||
};
|
||||
}
|
||||
|
||||
const result = await scriptDownloaderService.checkScriptExists(script);
|
||||
return {
|
||||
success: true,
|
||||
...result
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error in checkScriptFiles:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to check script files',
|
||||
ctExists: false,
|
||||
installExists: false,
|
||||
files: []
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user