diff --git a/online/src/app/classic/menus/filemenu.jsx b/online/src/app/classic/menus/filemenu.jsx index 8d41d119a..3251d06cb 100644 --- a/online/src/app/classic/menus/filemenu.jsx +++ b/online/src/app/classic/menus/filemenu.jsx @@ -97,7 +97,34 @@ export const FileMenu = () => linkType: 'direct', extensions: ['.vzome'], success: (files) => { - fetchDesignUrl( files[0].link, { preview: false, debug: false } ); + const url = files[ 0 ] .link .toLowerCase(); + setState( 'ignoreDesignName', true ); // transient, means we'll still have an untitled design after the fetch + fetchDesignUrl( url, { preview: false, debug: false } ); + + const name = files[ 0 ] .name; + if ( name && name .toLowerCase() .endsWith( '.vzome' ) ) { + setState( 'designName', name .substring( 0, name.length - 6 ) ); + setState( 'sharing', 'title', name .replaceAll( '-', ' ' ) ); + } + + /* + My personal Dropbox holds 100s of vZome files back to 2003. When I share them, + I want to capture the original date, which is encoded in the file path (usually): + .../vzome/attachments/2016/04-apr/10-Scott-deleteTest/testDeleteAndCut.vZome + */ + const ATTACHMENTS = 'vzome/attachments/'; + if ( url .includes( ATTACHMENTS ) ) { + const start = url .lastIndexOf( ATTACHMENTS ) + 18; + const relPath = url .substring( start ); + try { + const [ _, year, month, day ] = relPath .match( /([0-9]+)\/([0-9]+).*\/([0-9]+).*\// ); + const date = new Date( Number(year), Number(month)-1, Number(day) ); + setState( 'originalDate', date ); + console.log( 'Dropbox date:', date, 'for', year, month, day, relPath ); + } catch (error) { + console.log( 'Could not parse Dropbox path as date:', relPath ); + } + } }, } ); } diff --git a/online/src/app/framework/context/editor.jsx b/online/src/app/framework/context/editor.jsx index 3e0a7d098..6101b1533 100644 --- a/online/src/app/framework/context/editor.jsx +++ b/online/src/app/framework/context/editor.jsx @@ -78,7 +78,7 @@ const EditorProvider = props => case 'TEXT_FETCHED': { // we receive this event twice per fetch? let { name } = data.payload; - if ( name && name .endsWith( '.vZome' ) ) { + if ( name && name .toLowerCase() .endsWith( '.vzome' ) ) { if ( !state.ignoreDesignName ) { name = name .substring( 0, name.length - 6 ); setState( 'designName', name ); // cooperatively managed by both worker and client @@ -98,7 +98,6 @@ const EditorProvider = props => case 'CONTROLLER_CREATED': setState( { - ...initialState(), workerReady: true, controller: { __store: store, __path: [] } } ); @@ -195,7 +194,7 @@ const EditorProvider = props => { const { capture } = capturer(); const name = state?.designName || 'untitled'; - const config = { ...unwrap( state.sharing ), blog, publish }; + const config = { ...unwrap( state.sharing ), blog, publish, originalDate: state.originalDate }; return new Promise( ( resolve, reject ) => { new Promise((resolve, _) => { @@ -221,6 +220,7 @@ const EditorProvider = props => resetScenes(); setSceneIndex( 0 ); setState( 'source', { type: 'file', data: file } ); + setState( 'originalDate', null ); // NOT loaded from my Dropbox workerClient .postMessage( actions.openDesignFile( file, debug ) ); } @@ -230,6 +230,7 @@ const EditorProvider = props => resetScenes(); setSceneIndex( 0 ); setState( 'source', { type: 'url', data: url } ); + setState( 'originalDate', null ); // NOT loaded from my Dropbox workerClient .postMessage( actions.fetchDesign( url, config ) ); } diff --git a/online/src/worker/vzome-worker-static.js b/online/src/worker/vzome-worker-static.js index b60abdeb4..a464997d5 100644 --- a/online/src/worker/vzome-worker-static.js +++ b/online/src/worker/vzome-worker-static.js @@ -258,15 +258,15 @@ const exportPreview = ( camera, lighting ) => const shareToGitHub = async ( target, config, data, report ) => { const { orgName, repoName, branchName } = target; - const { title, description, blog, publish, style } = config; + const { title, description, blog, publish, style, originalDate } = config; const { name, camera, lighting, image } = data; const preview = exportPreview( camera, lighting ); importLegacy() .then( module => { const xml = design.wrapper .serializeVZomeXml( lighting, camera ); - const now = new Date() .toISOString(); - const date = now .substring( 0, 10 ); - const time = now .substring( 11 ) .replaceAll( ':', '-' ) .replaceAll( '.', '-' ); + const creation = ( originalDate || new Date() ) .toISOString(); + const date = creation .substring( 0, 10 ); + const time = creation .substring( 11 ) .replaceAll( ':', '-' ) .replaceAll( '.', '-' ); const shareData = new module .vzomePkg.core.exporters.GitHubShare( title, date, time, xml, image, preview ); const uploads = [];