Skip to content

Commit

Permalink
Merge pull request #934 from vorth/dropbox-dates
Browse files Browse the repository at this point in the history
Preserving data from Dropbox
  • Loading branch information
vorth authored Dec 11, 2024
2 parents f130e46 + bdfedd7 commit 9d5c5e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
29 changes: 28 additions & 1 deletion online/src/app/classic/menus/filemenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
},
} );
}
Expand Down
7 changes: 4 additions & 3 deletions online/src/app/framework/context/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,7 +98,6 @@ const EditorProvider = props =>

case 'CONTROLLER_CREATED':
setState( {
...initialState(),
workerReady: true,
controller: { __store: store, __path: [] }
} );
Expand Down Expand Up @@ -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, _) => {
Expand All @@ -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 ) );
}

Expand All @@ -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 ) );
}

Expand Down
8 changes: 4 additions & 4 deletions online/src/worker/vzome-worker-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 9d5c5e8

Please sign in to comment.