This commit is contained in:
Saifeddine ALOUI 2024-03-24 18:09:18 +01:00
parent a3c57bd6f9
commit 5d2be7b3e7
7 changed files with 57 additions and 11 deletions

View File

@ -167,6 +167,52 @@ async def open_file(file_path: FilePath):
return {"status":False,"error":str(ex)}
class FilePath(BaseModel):
path: Optional[str] = Field(None, max_length=500)
@router.post("/open_folder")
async def open_folder(file_path: FilePath):
"""
Opens a folder
:param file_path: The file path object.
:return: A JSON response with the status of the operation.
"""
if lollmsElfServer.config.headless_server_mode:
return {"status":False,"error":"Open file is blocked when in headless mode for obvious security reasons!"}
if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1":
return {"status":False,"error":"Open file is blocked when the server is exposed outside for very obvious reasons!"}
if lollmsElfServer.config.turn_on_open_file_validation:
if not show_yes_no_dialog("Validation","Do you validate the opening of a file?"):
return {"status":False,"error":"User refused the opeining file!"}
forbid_remote_access(lollmsElfServer)
try:
# Validate the 'path' parameter
path = file_path.path
# Sanitize the 'path' parameter
path = os.path.realpath(path)
# Use subprocess.Popen to safely open the file
if platform.system() == 'Windows':
subprocess.Popen(f'explorer "{path}"')
elif platform.system() == 'Linux':
subprocess.run(['xdg-open', str(path)], check=True)
elif platform.system() == 'Darwin':
subprocess.run(['open', str(path)], check=True)
return {"status": True, "execution_time": 0}
except Exception as ex:
trace_exception(ex)
lollmsElfServer.error(ex)
return {"status":False,"error":str(ex)}
class OpenCodeFolderInVsCodeRequestModel(BaseModel):
client_id: str = Field(...)
discussion_id: Optional[int] = Field(None, gt=0)

@ -1 +1 @@
Subproject commit 4bcbd59f302b5f81b74ac944d654e5f6a4784e23
Subproject commit ac18f25ffa826a10b712871118cbad4456224444

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-3c3c0f77.js"></script>
<link rel="stylesheet" href="/assets/index-51cca12d.css">
<script type="module" crossorigin src="/assets/index-886b6042.js"></script>
<link rel="stylesheet" href="/assets/index-f8651315.css">
</head>
<body>
<div id="app"></div>

View File

@ -683,7 +683,7 @@ export default {
setting_name: "binding_name",
setting_value: selectedBinding.name
}).then(async (response) => {
this.$store.state.messageBox.hideBlockingMessage()
this.$store.state.messageBox.hideMessage()
console.log("UPDATED");
console.log(response);
await this.$store.dispatch('refreshBindings');
@ -693,7 +693,7 @@ export default {
this.$store.state.toast.showToast(`Binding changed to ${this.currentBinding.name}`,4,true)
this.selecting_binding=false
}).catch(err=>{
this.$store.state.messageBox.hideBlockingMessage()
this.$store.state.messageBox.hideMessage()
this.$store.state.toast.showToast(`Error ${err}`,4,true)
this.selecting_binding=false
});
@ -708,7 +708,7 @@ export default {
setting_name: "model_name",
setting_value: selectedModel.name
}).then(async (response) => {
this.$store.state.messageBox.hideBlockingMessage()
this.$store.state.messageBox.hideMessage()
console.log("UPDATED");
console.log(response);
await this.$store.dispatch('refreshConfig');
@ -716,7 +716,7 @@ export default {
this.$store.state.toast.showToast(`Model changed to ${this.currentModel.name}`,4,true)
this.selecting_model=false
}).catch(err=>{
this.$store.state.messageBox.hideBlockingMessage()
this.$store.state.messageBox.hideMessage()
this.$store.state.toast.showToast(`Error ${err}`,4,true)
this.selecting_model=false
});

@ -1 +1 @@
Subproject commit 24d4ad5b6ca956169e685adb754e6645a268cbcf
Subproject commit fe46dddf82563c46a59107bd18ea4a86d6953551