Skip to content
Permalink
Browse files

fix issue with odd characters in file names

  • Loading branch information...
ThatJoeMoore committed May 5, 2019
1 parent 39ee623 commit 7cdc440405b2058ac16c290f3ad5e7f8b13d4b5c
Showing with 1,849 additions and 1,097 deletions.
  1. +1 −0 .gitignore
  2. +4 −4 assembler/index.js
  3. +0 −1 assembler/package.json
  4. +33 −2 assembler/src/build-layout.js
  5. +25 −451 assembler/src/upload-files.js
  6. +1,786 −638 assembler/yarn.lock
  7. +0 −1 main-config.yml
@@ -1,4 +1,5 @@
.github-api-key
.handel-extensions/

handel-secrets.txt

@@ -24,15 +24,15 @@ const path = require('path');
const log = require('winston');
const axios = require('axios');

log.transport

const loadGithubCredentials = require('./src/util/load-github-credentials');
const GithubProvider = require('./src/providers/github-provider');

const assembleManifest = require('./src/assemble-manifest');
const planActions = require('./src/plan-actions');
const downloadSources = require('./src/download-sources');
const assembleArtifacts = require('./src/copy-resources');
const buildMeta = require('./src/build-meta');
const {uploadFiles2} = require('./src/upload-files');
const {uploadFiles} = require('./src/upload-files');
const buildLayout = require('./src/build-layout');
const constants = require('./src/constants');
const {NoopMessager, SlackMessager} = require('./src/messagers');
@@ -120,7 +120,7 @@ module.exports = async function cdnAssembler(config, targetBucket, opts) {
// const versionManifests = await buildMeta(newManifest, assembledDir);
//
log.info("----- Uploading Files -----");
await uploadFiles2(buildContext, filesystem, actions, newManifest);
await uploadFiles(buildContext, filesystem, actions, newManifest);
// await uploadFiles(oldManifest, newManifest, versionManifests, actions, targetBucket, assembledDir, cdnHost, dryRun);

await messages.sendSuccess(buildContext);
@@ -44,7 +44,6 @@
"p-queue": "^2.3.1",
"request": "^2.81.0",
"request-promise-native": "^1.0.4",
"s3": "^4.4.0",
"semver": "^5.4.1",
"type-detect": "^4.0.3",
"winston": "^2.3.1",
@@ -80,7 +80,8 @@ module.exports = async function buildLayout(buildContext, oldManifest, newManife
sha = 'redirect';
} else if (it.empty) {
sha = 'empty';
} if (it.hashes) {
}
if (it.hashes) {
sha = it.hashes.sha512.hex;
} else if (it.contents) {
sha = util.hash('sha512', Buffer.from(it.contents)).hex;
@@ -348,7 +349,7 @@ async function processSourceFile(ver, file, cacheControl) {
return {
name: file.name,
contentPath: from,
cdnPath: file.to,
cdnPath: sanitizeFileName(file.to),
type,
size,
hashes,
@@ -365,6 +366,36 @@ async function processSourceFile(ver, file, cacheControl) {
}
}

const replacements = [
[/;/, 'semicolon'],
[/,/, 'comma'],
[/\?/, 'question'],
[/:/, 'colon'],
[/@/, 'at'],
[/&/, 'and'],
[/=/, 'equals'],
[/\+/, 'plus'],
[/\$/, 'dollar'],
[/!/, 'exclamation'],
[/\*/, 'asterisk'],
[/'/, 'apostrophe'],
[/\(/, 'open_paren'],
[/\)/, 'close_paren'],
[/#/, 'pound']
];

function sanitizeFileName(name) {
//Prefer encoding spaces as _, some things as names, then url-encode ALL THE THINGS! 🧹🙋✊
const replaced = replacements.reduce((prev, cur) => {
const [pattern, name] = cur;
return prev.replace(pattern, `__${name}__`)
}, name.replace(/\s/, '_'));

return encodeURI(
replaced
);
}

function processVersionAliasFiles(libId, lib, ver, verPrefix, verFiles) {
let defaultCacheControl = aliasCacheControlFor(libId, ver);
return flatMap(Object.entries(ver.aliases), ([aliasName, alias]) => {

0 comments on commit 7cdc440

Please sign in to comment.
You can’t perform that action at this time.