Sharing models

This commit is contained in:
JannisX11 2020-11-13 20:43:22 +01:00
parent e25262df0a
commit 2f9c8b3d32
4 changed files with 71 additions and 1 deletions

View File

@ -2,7 +2,7 @@ const EditSession = {
active: false,
hosting: false,
BBKey: '1h3sq3hoj6vfkh',
ip: '104.248.38.177',
ip: 'blckbn.ch',
clients: {},
placeholder_names: ['R2D2', 'Tin Man', 'C3PO', 'WALL-E', 'EVE', 'BB-8', 'B1 Battle Droid', 'ASIMO', 'Atlas'],
start() {

View File

@ -508,6 +508,7 @@ const MenuBar = {
'export_obj',
'export_gltf',
'upload_sketchfab',
'share_model',
]},
'export_over',
'export_asset_archive',

View File

@ -945,4 +945,66 @@ BARS.defineActions(function() {
uploadSketchfabModel()
}
})
new Action('share_model', {
name: 'Share',
icon: 'share',
condition: () => Cube.all.length,
click() {
var dialog = new Dialog({
id: 'share',
title: 'Share Model',
form: {
expire_time: {label: 'Expire Time', type: 'select', default: '2d', options: {
'10m': '10 Minutes',
'1h': '1 Hour',
'1d': '1 Day',
'2d': '2 Days',
'1w': '1 Week',
}},
},
onConfirm: function(formResult) {
let expire_time = formResult.expire_time;
let model = Codecs.project.compile({compressed: false});
$.ajax({
url: 'https://blckbn.ch/api/model',
data: JSON.stringify({ expire_time, model }),
cache: false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
success: function(response) {
let link = `https://blckbn.ch/${response.id}`
console.log(response, link)
if (isApp) {
clipboard.writeText(link)
Blockbench.showQuickMessage('Link copied to Clipboard')
} else {
Blockbench.showMessageBox({
title: 'Model uploaded',
message: `[${link}](${link})`,
})
}
},
error: function(response) {
console.log(response);
Blockbench.showQuickMessage('Error uploading', 1500)
console.error(response);
}
})
dialog.hide()
}
})
dialog.show()
}
})
})

View File

@ -39,6 +39,13 @@ function loadInfoFromURL() {
Codecs.project.load(model, {path: ''});
}
})
} else if (location.hash.substr(1, 2) == 'm=') {
$.getJSON(`https://blckbn.ch/api/models/${location.hash.substr(3)}`, (model) => {
if (showSaveDialog()) {
resetProject();
Codecs.project.load(model, {path: ''});
}
})
}
}