Skip to content

Commit

Permalink
use filenamify again (but without the need for polyfills)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Sep 26, 2020
1 parent 5664a0f commit e476212
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 36 deletions.
4 changes: 2 additions & 2 deletions adminSite/client/DatasetEditPage.tsx
Expand Up @@ -11,7 +11,7 @@ import {
} from "mobx"
import * as lodash from "lodash"
import { Prompt, Redirect } from "react-router-dom"
import sanitizeFilename from "sanitize-filename"
import filenamify from "filenamify" // browser-only export from `filenamify`, without requiring `path` polyfills
import { format } from "timeago.js"

import {
Expand Down Expand Up @@ -464,7 +464,7 @@ class DatasetEditor extends React.Component<{ dataset: DatasetPageData }> {
return `https://github.com/${
this.context.admin.settings.GITHUB_USERNAME
}/owid-datasets/tree/master/datasets/${encodeURIComponent(
sanitizeFilename(this.props.dataset.name)
filenamify(this.props.dataset.name)
)}`
}

Expand Down
4 changes: 2 additions & 2 deletions adminSite/server/adminRouter.tsx
@@ -1,7 +1,7 @@
// Misc non-SPA views
import { Request, Response, Router } from "express"
import rateLimit from "express-rate-limit"
import sanitizeFilename from "sanitize-filename"
import filenamify from "filenamify"
import * as React from "react"
import { getConnection } from "typeorm"

Expand Down Expand Up @@ -210,7 +210,7 @@ adminRouter.get("/datasets/:datasetId.csv", async (req, res) => {
const datasetName = (
await db.get(`SELECT name FROM datasets WHERE id=?`, [datasetId])
).name
res.attachment(sanitizeFilename(datasetName) + ".csv")
res.attachment(filenamify(datasetName) + ".csv")

return Dataset.writeCSV(datasetId, res)
})
Expand Down
9 changes: 2 additions & 7 deletions adminSite/server/utils/gitDataExport.ts
@@ -1,11 +1,6 @@
import * as path from "path"
import * as fs from "fs-extra"
import {
JsonError,
sanitizeFilename,
exec,
execFormatted,
} from "utils/server/serverUtil"
import { JsonError, execFormatted, filenamify } from "utils/server/serverUtil"
import { Dataset } from "db/model/Dataset"
import { Source } from "db/model/Source"
import { GIT_DATASETS_DIR, TMP_DIR } from "serverSettings"
Expand Down Expand Up @@ -63,7 +58,7 @@ export async function syncDatasetToGitRepo(
const { oldDatasetName, commitName, commitEmail, commitOnly } = options

const oldDatasetFilename = oldDatasetName
? sanitizeFilename(oldDatasetName)
? filenamify(oldDatasetName)
: undefined

const datasetRepo = options.transaction
Expand Down
4 changes: 2 additions & 2 deletions db/model/Dataset.ts
Expand Up @@ -11,7 +11,7 @@ import { Writable } from "stream"
import { User } from "./User"
import { Source } from "./Source"
import { Variable } from "./Variable"
import { csvRow, slugify, sanitizeFilename } from "utils/server/serverUtil"
import { csvRow, slugify, filenamify } from "utils/server/serverUtil"
import * as db from "db/db"

@Entity("datasets")
Expand Down Expand Up @@ -109,7 +109,7 @@ export class Dataset extends BaseEntity {
}

get filename() {
return sanitizeFilename(this.name)
return filenamify(this.name)
}

get slug() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -133,6 +133,7 @@
"express-rate-limit": "^5.1.3",
"fibers": "^5.0.0",
"file-loader": "^6.1.0",
"filenamify": "https://github.com/MarcelGerber/filenamify",
"fs-extra": "^9.0.1",
"fuzzyset": "^1.0.5",
"fuzzysort": "^1.1.4",
Expand Down Expand Up @@ -178,7 +179,6 @@
"react-tag-autocomplete": "https://github.com/mispy/react-tags",
"react-zoom-pan-pinch": "https://github.com/mlbrgl/react-zoom-pan-pinch",
"reflect-metadata": "^0.1.13",
"sanitize-filename": "^1.6.3",
"sass": "^1.26.10",
"sass-loader": "^10.0.2",
"sharp": "^0.23.0",
Expand Down
4 changes: 2 additions & 2 deletions utils/server/serverUtil.tsx
Expand Up @@ -113,5 +113,5 @@ export async function execFormatted(cmd: string, args: string[]) {
await exec(formatCmd)
}

import sanitizeFilename from "sanitize-filename"
export { sanitizeFilename }
import filenamify from "filenamify"
export { filenamify }
29 changes: 9 additions & 20 deletions yarn.lock
Expand Up @@ -9400,6 +9400,14 @@ filenamify@^2.0.0:
strip-outer "^1.0.0"
trim-repeated "^1.0.0"

"filenamify@https://github.com/MarcelGerber/filenamify":
version "4.2.0"
resolved "https://github.com/MarcelGerber/filenamify#13cf5f36affbede0c54fb3edef7063c0546b68b9"
dependencies:
filename-reserved-regex "^2.0.0"
strip-outer "^1.0.1"
trim-repeated "^1.0.0"

filesize@6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-6.0.1.tgz#f850b509909c7c86f7e450ea19006c31c2ed3d2f"
Expand Down Expand Up @@ -17434,13 +17442,6 @@ sane@^4.0.3:
minimist "^1.1.1"
walker "~1.0.5"

sanitize-filename@^1.6.3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.3.tgz#755ebd752045931977e30b2025d340d7c9090378"
integrity sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==
dependencies:
truncate-utf8-bytes "^1.0.0"

sass-loader@^10.0.2:
version "10.0.2"
resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-10.0.2.tgz#c7b73010848b264792dd45372eea0b87cba4401e"
Expand Down Expand Up @@ -18468,7 +18469,7 @@ strip-json-comments@^3.0.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

strip-outer@^1.0.0:
strip-outer@^1.0.0, strip-outer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
integrity sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==
Expand Down Expand Up @@ -19143,13 +19144,6 @@ trough@^1.0.0:
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.4.tgz#3b52b1f13924f460c3fbfd0df69b587dbcbc762e"
integrity sha512-tdzBRDGWcI1OpPVmChbdSKhvSVurznZ8X36AYURAcl+0o2ldlCY2XPzyXNNxwJwwyIU+rIglTCG4kxtNKBQH7Q==

truncate-utf8-bytes@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b"
integrity sha1-QFkjkJWS1W94pYGENLC3hInKXys=
dependencies:
utf8-byte-length "^1.0.1"

ts-dedent@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-1.1.1.tgz#68fad040d7dbd53a90f545b450702340e17d18f3"
Expand Down Expand Up @@ -19769,11 +19763,6 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

utf8-byte-length@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61"
integrity sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=

util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit e476212

Please sign in to comment.