Skip to content

Commit

Permalink
svx failing to ingest due to periods in EDAN titles (#571)
Browse files Browse the repository at this point in the history
(new) additional logging working with asset versions
(new) sanitizeFileName replaces periods with '-'
  • Loading branch information
EMaslowskiQ authored Feb 1, 2024
1 parent 684df40 commit 84089fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions server/storage/interface/AssetStorageAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class AssetStorageAdapter {
const commitWriteStreamInput: STORE.CommitWriteStreamInput = { storageKey, storageHash };

LOG.info(`AssetStorageAdapter.commitNewAssetVersion idAsset ${asset.idAsset}: ${commitWriteStreamInput.storageKey}`, LOG.LS.eSTR);
// LOG.info(`AssetStorageAdapter.commitNewAssetVersion write stream. (${H.Helpers.JSONStringify(commitWriteStreamInput)})`, LOG.LS.eDEBUG);

const storage: IStorage | null = await StorageFactory.getInstance(); /* istanbul ignore next */
if (!storage) {
Expand All @@ -213,7 +214,7 @@ export class AssetStorageAdapter {

const resStorage: STORE.CommitWriteStreamResult = await storage.commitWriteStream(commitWriteStreamInput);
if (!resStorage.success) {
LOG.error(resStorage.error, LOG.LS.eSTR);
LOG.error(`AssetStorageAdapter.commitNewAssetVersion cannot commit write stream: ${resStorage.error}. (${H.Helpers.JSONStringify(commitWriteStreamInput)})`, LOG.LS.eSTR);
return { assets: null, assetVersions: null, success: false, error: resStorage.error };
}

Expand Down Expand Up @@ -1058,7 +1059,8 @@ export class AssetStorageAdapter {
});

if (!comRes || !comRes.success || !comRes.assets || comRes.assets.length != 1 || !comRes.assetVersions || comRes.assetVersions.length != 1) {
const error: string = `AssetStorageAdapter.ingestStreamOrFile Unable to commit asset: ${comRes ? comRes.error : ''}`;
// LOG.info(`AssetStorageAdapter.ingestStreamOrFile commit asset: ${comRes ? comRes.error : ''}. (ISI: ${H.Helpers.JSONStringify(ISI)} | Result: ${H.Helpers.JSONStringify(comRes)})`,LOG.LS.eDEBUG);
const error: string = `AssetStorageAdapter.ingestStreamOrFile Unable to commit asset: ${comRes ? comRes.error : ''}. (ISI: ${H.Helpers.JSONStringify(ISI)} | Result: ${H.Helpers.JSONStringify(comRes)})`;
LOG.error(error, LOG.LS.eSTR);
return { success: false, error };
}
Expand Down
9 changes: 7 additions & 2 deletions server/utils/nameHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ export class NameHelpers {
//basic_clean: return sanitize(fileName.replace(/[\s,]/g, '_').replace(/[^a-zA-Z0-9\-_.]/g, '-'));
//legacy: return sanitize(fileName.replace(/:/g, '-').replace(/ /g, '_'), { replacement: '_' });

return fileName.replace(/[\s,]/g, '_') // replace spaces and commas
const result = fileName.replace(/[\s,]/g, '_') // replace spaces and commas
.replace(/[^\x00-\x7F]/g, '') // remove non-ascii characters
.replace(/['`]/g, '') // remove all apostrophes and single quotes
.replace(/[^a-zA-Z0-9\-_.]/g, '-'); // replace special characters except for certain ones
.replace(/\./g, '-') // replace periods with hyphens
.replace(/[^a-zA-Z0-9\-_]/g, '-') // remove everything except letters, digits, hyphens, and underscores
.replace(/\W$/, ''); // remove the last character if it's not alphanumeric or an underscore (cleanup)
LOG.info(`nameHelpers.sanitizeFileNmae (${fileName} -> ${result})`,LOG.LS.eDEBUG);

return result;
}
/* eslint-enable no-control-regex */

Expand Down

0 comments on commit 84089fc

Please sign in to comment.