Skip to content

Commit 74bb5a8

Browse files
fix. ftp
1 parent 3dde89a commit 74bb5a8

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

src/lib/run.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,14 @@ async function run(
177177
const reqId = req.requestId;
178178
let reqPath = req.path.substring(1);
179179

180+
console.log(req)
181+
180182
//if (!reqPath || reqPath.endsWith("/")) {}
181183

184+
if (!reqPath) {
185+
reqPath = "/"+filename
186+
}
187+
182188
if (!reqPath) {
183189
console.error("Request path is empty");
184190
webServer?.send(reqId, {
@@ -490,6 +496,9 @@ async function run(
490496
}
491497

492498
function removePrefix(str, prefix) {
499+
console.log("-----------------")
500+
console.log("removing " + prefix + " from " + str)
501+
console.log("-----------------")
493502
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
494503
}
495504

@@ -498,27 +507,44 @@ async function run(
498507
*/
499508
function openBrowser() {
500509
console.log("Path name", pathName);
501-
console.log("Filename", filename);
502-
510+
console.log("File parent",pathName)
511+
503512
//get the project url
504513
let rootFolder = addedFolder[0].url
505514

515+
if (rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) {
516+
if (rootFolder.includes("?")) {
517+
rootFolder = rootFolder.split("?")[0];
518+
}
519+
}
520+
521+
if (pathName.startsWith("ftp:") || pathName.startsWith("sftp:")) {
522+
if (pathName.includes("?")) {
523+
pathName = pathName.split("?")[0];
524+
}
525+
}
526+
527+
//append path data
506528
if (rootFolder === "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome") {
507529
rootFolder = "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome::/data/data/com.termux/files/home/"
508530
}
509531

532+
console.log("Root", rootFolder)
533+
510534
//remove the project prefix from the file parent path name
511535
//this will give us the path relative to the project folder
512536
/** @type {string} */
513-
let filePath = removePrefix(pathName, rootFolder)
537+
let filePath = removePrefix(pathName, rootFolder)
514538

515-
if (!rootFolder.includes("::")) {
516-
filePath = pathName.split("::")[1];
539+
let oldFilePath = filePath
540+
filePath = pathName.split("::")[1];
541+
if (!filePath) {
542+
filePath = oldFilePath
517543
}
518544

545+
console.log("File path", filePath);
546+
519547

520-
console.log("Root", rootFolder)
521-
console.log("File parent",pathName)
522548

523549
//add the filename to the path
524550
//this will give us the full path to the file relative to the project folder
@@ -528,21 +554,15 @@ async function run(
528554
filePath = filePath + "/" + filename;
529555
}
530556

531-
console.log(addedFolder[0])
532-
533-
console.log("File path", filePath);
534-
535-
let path = removePrefix(removePrefix(removePrefix(filePath, rootFolder),"primary:"+addedFolder[0].title),"/")
536-
537-
//path = pathName.split("::")[0]+path
538557

539-
558+
let path = removePrefix(removePrefix(removePrefix(filePath, rootFolder),"primary:"+addedFolder[0].title),"/")
540559

541560
console.log("Path", path);
542561

543562

544563
const src = `http://localhost:${port}/${path}`;
545564

565+
546566
console.log("Src", src);
547567
if (target === "browser") {
548568
system.openInBrowser(src);
@@ -553,4 +573,4 @@ async function run(
553573
}
554574
}
555575

556-
export default run;
576+
export default run;

0 commit comments

Comments
 (0)