Skip to content

Commit

Permalink
Add domain support for slk
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Nov 13, 2023
1 parent c073ed9 commit c78a4cc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/entries/chunks/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function _slk(k: any, lh: any, rd: any) {
if (!v) return;
let index = v.indexOf(";");
if (index < 0) return;
if(!checkPrefix(v.substring(0, index))) return;
v = v.substring(index + 1);
v.split(",").forEach(s => {
let i = s.indexOf("=");
Expand All @@ -49,6 +50,22 @@ function _slk(k: any, lh: any, rd: any) {
}
});
}
function checkPrefix(prefix: string): boolean {
if(!prefix) return true;
const s = "domains:";
const index = prefix.indexOf(s);
if(index < 0) return true;
const ds = prefix.substring(index + s.length).toLowerCase().split(",");
if(!Array.isArray(ds) || ds.length === 0) return true;
if(typeof window !== "undefined" && !!window.location && !!window.location.hostname) {
const hn = window.location.hostname.toLowerCase();
ds.push("localhost");
for(let i = 0; i < ds.length; i ++) {
if(hn.indexOf(ds[i]) > -1) return true;
}
}
return false;
}

export { settings, ISurveyEnvironment } from "../../settings";
export { Helpers, HashTable } from "../../helpers";
Expand Down

0 comments on commit c78a4cc

Please sign in to comment.