Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:undev-studio/cables_dev into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
pandrr committed Apr 4, 2024
2 parents 53bf0c9 + 2219600 commit b56c893
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"ecmaVersion": 2020
},
"rules": {
"no-useless-concat": 0,
"object-property-newline": "error",
"global-require": 1,
"no-compare-neg-zero": 0,
Expand Down
10 changes: 5 additions & 5 deletions shared/api/utils/shared_doc_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ export default class SharedDocUtil extends SharedUtil
}
}

addOpsToLookup(ops)
addOpsToLookup(ops, clearFiles = false)
{
if (!ops) return;
let writeToFile = false;
if (!this.cachedLookup) this.cachedLookup = {};
if (!this.cachedLookup.ids) this.cachedLookup.ids = {};
if (!this.cachedLookup.names) this.cachedLookup.names = {};
if (clearFiles || !this.cachedLookup) this.cachedLookup = {};
if (clearFiles || !this.cachedLookup.ids) this.cachedLookup.ids = {};
if (clearFiles || !this.cachedLookup.names) this.cachedLookup.names = {};
ops.forEach((op) =>
{
if (op.id && op.name)
Expand Down Expand Up @@ -666,7 +666,7 @@ export default class SharedDocUtil extends SharedUtil
docs = docs.concat(this.getOpDocsForCollections(opNames));

// make sure all ops are in lookup table
this.addOpsToLookup(docs);
this.addOpsToLookup(docs, true);
if (cb) cb(docs);
}

Expand Down
34 changes: 34 additions & 0 deletions shared/api/utils/shared_files_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "fs";
import path from "path";
import moment from "moment";
import sizeOfImage from "image-size";
import sanitizeFileName from "sanitize-filename";
import { UtilProvider } from "./util_provider.js";
import SharedUtil from "./shared_util.js";

Expand Down Expand Up @@ -174,4 +175,37 @@ export default class SharedFilesUtil extends SharedUtil

return icon;
}

realSanitizeFilename(_filename)
{
let filename = sanitizeFileName(_filename);
// eslint-disable-next-line no-control-regex
filename = filename.replace(/[^\x00-\x7F]/g, "_");
filename = filename.replace(/ /g, "_");
filename = filename.replace(/&/g, "_");
filename = filename.replace(/;/g, "_");
filename = filename.replace(/'/g, "_");
filename = filename.replace(/!/g, "_");
filename = filename.replace(/#/g, "_");
filename = filename.replace(/\$/g, "_");
filename = filename.replace(/\(/g, "_");
filename = filename.replace(/\)/g, "_");

const suffix = this.getSuffix(filename);
if (suffix) filename = filename.replace(suffix.toUpperCase(), suffix); // force lowercase file extensions

return filename;
}

getSuffix(filename)
{
let suffix = null;

if (!suffix)
for (const k in this.FILETYPES)
for (let j = 0; j < this.FILETYPES[k].length; j++)
if (filename.toLowerCase().endsWith(this.FILETYPES[k][j])) suffix = this.FILETYPES[k][j];

return suffix;
}
}

0 comments on commit b56c893

Please sign in to comment.