diff --git a/manifest.json b/manifest.json index 21cc29d..6fec098 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-tweet-to-markdown", "name": "Tweet to Markdown", - "version": "1.1.2", + "version": "1.1.3", "minAppVersion": "0.12.16", "description": "Save tweets as Markdown files, along with their images, polls, etc.", "author": "kbravh", diff --git a/package.json b/package.json index aea1053..c5a553b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-tweet-to-markdown", - "version": "1.1.2", + "version": "1.1.3", "description": "Save tweets as beautiful markdown files in Obsidian (https://obsidian.md)", "main": "main.js", "engines": { @@ -25,7 +25,5 @@ "tslib": "^2.2.0", "typescript": "^4.2.4" }, - "dependencies": { - "sanitize-filename": "^1.6.3" - } + "dependencies": {} } diff --git a/src/util.ts b/src/util.ts index 35ebed2..d8b3704 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,7 +1,6 @@ import {App, normalizePath, request, TAbstractFile} from 'obsidian' import {Media, Poll, Tweet} from './models' import {DownloadManager} from './downloadManager' -import sanitize from 'sanitize-filename' import TTM from 'main' import {TTMSettings} from './settings' @@ -83,6 +82,27 @@ export const createPollTable = (polls: Poll[]): string[] => { }) } +/** + * Filename sanitization. Credit: parshap/node-sanitize-filename + * Rewrite to allow functionality on Obsidian mobile. + */ +const illegalRe = /[/?<>\\:*|"]/g +// eslint-disable-next-line no-control-regex +const controlRe = /[\x00-\x1f\x80-\x9f]/g +const reservedRe = /^\.+$/ +const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i +const windowsTrailingRe = /[. ]+$/ + +export const sanitizeFilename = (filename: string): string => { + filename = filename + .replace(illegalRe, '') + .replace(controlRe, '') + .replace(reservedRe, '') + .replace(windowsReservedRe, '') + .replace(windowsTrailingRe, '') + return filename +} + /** * Creates a filename based on the tweet and the user defined options. * @param {Tweet} tweet - The entire tweet object from the Twitter v2 API @@ -96,7 +116,7 @@ export const createFilename = (tweet: Tweet, filename = ''): string => { filename = filename.replace('[[handle]]', tweet.includes.users[0].username) filename = filename.replace('[[id]]', tweet.data.id) filename = filename.replace('[[text]]', tweet.data.text) - return sanitize(filename) + '.md' + return sanitizeFilename(filename) + '.md' } /** diff --git a/versions.json b/versions.json index 5035af4..db0d43d 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.1.2": "0.12.16" + "1.1.3": "0.12.16" } diff --git a/yarn.lock b/yarn.lock index df43666..1429992 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1880,13 +1880,6 @@ rxjs@^6.6.0: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -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" - semver-diff@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-3.1.1.tgz#05f77ce59f325e00e2706afd67bb506ddb1ca32b" @@ -2076,13 +2069,6 @@ trim-newlines@^3.0.0: resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144" integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw== -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" - tslib@^1.8.1, tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" @@ -2185,11 +2171,6 @@ url-parse-lax@^3.0.0: dependencies: prepend-http "^2.0.0" -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= - v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"