Skip to content

Commit

Permalink
Merge pull request #426 from vgteam/relative-links
Browse files Browse the repository at this point in the history
Use relative paths in link to view
  • Loading branch information
adamnovak authored May 3, 2024
2 parents b6de77d + 234a75c commit b76452a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,6 @@ async function getChunkedData(req, res, next) {
if (req.removeSequences){
removeNodeSequencesInPlace(req.graph)
}
console.log("remove sequences? ", req.graph)
req.region = [rangeRegion.start, rangeRegion.end];

// We might not have the path we are referencing on appearing first.
Expand Down Expand Up @@ -1429,6 +1428,23 @@ assert(
"Scratch path is not acceptable; does it contain .. or //?"
);

/**
* Convert an absolute path to a path relative to the current directory, if it
* would be an allowed path (i.e. not include ..). If not, pass threough the
* original path.
*
* This is the path we should send to the client, to keep the server's base
* directory out of the path unless it is needed.
*/
function toClientPath(absPath) {
let relPath = path.relative('.', absPath);
if (isAllowedPath(relPath)) {
return relPath;
} else {
return absPath;
}
}

api.get("/getFilenames", (req, res) => {
console.log("received request for filenames");
const result = {
Expand All @@ -1439,18 +1455,18 @@ api.get("/getFilenames", (req, res) => {
if (isAllowedPath(MOUNTED_DATA_PATH)) {
// list files in folder
fs.readdirSync(MOUNTED_DATA_PATH).forEach((file) => {
const absPath = path.resolve(MOUNTED_DATA_PATH, file);
const clientPath = toClientPath(path.resolve(MOUNTED_DATA_PATH, file));
if (endsWithExtensions(file, GRAPH_EXTENSIONS)) {
result.files.push({ trackFile: absPath, trackType: "graph" });
result.files.push({ trackFile: clientPath, trackType: "graph" });
}
if (endsWithExtensions(file, HAPLOTYPE_EXTENSIONS)) {
result.files.push({ trackFile: absPath, trackType: "haplotype" });
result.files.push({ trackFile: clientPath, trackType: "haplotype" });
}
if (file.endsWith(".sorted.gam")) {
result.files.push({ trackFile: absPath, trackType: "read" });
result.files.push({ trackFile: clientPath, trackType: "read" });
}
if (file.endsWith(".bed")) {
result.bedFiles.push(absPath);
result.bedFiles.push(clientPath);
}
});
} else {
Expand Down

0 comments on commit b76452a

Please sign in to comment.