Merge branch 'sharing' into 3.8

This commit is contained in:
JannisX11 2021-02-24 18:02:43 +01:00
commit c14467da21
5 changed files with 88 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

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

View File

@ -597,4 +597,64 @@ BARS.defineActions(function() {
uploadSketchfabModel()
}
})
new Action('share_model', {
icon: 'share',
condition: () => Cube.all.length,
click() {
var dialog = new Dialog({
id: 'share_model',
title: 'dialog.share_model.title',
form: {
expire_time: {label: 'dialog.share_model.expire_time', type: 'select', default: '2d', options: {
'10m': tl('dates.minutes', [10]),
'1h': tl('dates.hour', [1]),
'1d': tl('dates.day', [1]),
'2d': tl('dates.days', [2]),
'1w': tl('dates.week', [1]),
}},
info: {type: 'info', text: 'The model will be stored on the Blockbench servers during the duration specified above. [Learn how your data is protected](https://blockbench.net/blockbench-model-sharing-service/)'}
},
buttons: ['generic.share', 'dialog.cancel'],
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}`
if (isApp || navigator.clipboard) {
Clipbench.setText(link);
Blockbench.showQuickMessage('dialog.share_model.copied_to_clipboard');
} else {
Blockbench.showMessageBox({
title: 'dialog.share_model.title',
message: `[${link}](${link})`,
})
}
},
error: function(response) {
Blockbench.showQuickMessage('dialog.share_model.failed', 1500)
console.error(response);
}
})
dialog.hide()
}
})
dialog.show()
}
})
})

View File

@ -35,6 +35,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: ''});
}
})
}
}

View File

@ -34,6 +34,7 @@
"generic.rename": "Rename",
"generic.import": "Import",
"generic.export": "Export",
"generic.share": "Share",
"generic.download": "Download",
"generic.search": "Search",
"generic.help": "Help",
@ -52,6 +53,17 @@
"dates.this_week": "This Week",
"dates.weeks_ago": "%0 weeks ago",
"dates.minute": "%0 Minute",
"dates.minutes": "%0 Minutes",
"dates.hour": "%0 Hour",
"dates.hours": "%0 Hours",
"dates.day": "%0 Day",
"dates.days": "%0 Days",
"dates.week": "%0 Week",
"dates.weeks": "%0 Weeks",
"dates.year": "%0 Year",
"dates.years": "%0 Years",
"mode.start": "Start",
"mode.edit": "Edit",
"mode.paint": "Paint",
@ -378,6 +390,11 @@
"dialog.sketchfab_uploader.private": "Private (Pro)",
"dialog.sketchfab_uploader.password": "Password (Pro)",
"dialog.share_model.title": "Share Model",
"dialog.share_model.expire_time": "Expire Time",
"dialog.share_model.copied_to_clipboard": "Link copied to clipboard",
"dialog.share_model.failed": "Failed to upload model",
"dialog.model_stats.title": "Model Stats",
"dialog.model_stats.cubes": "Cubes",
"dialog.model_stats.locators": "Locators",
@ -740,6 +757,8 @@
"action.export_gltf.desc": "Export model and animations as glTF file to use in other 3D applications",
"action.upload_sketchfab": "Upload to Sketchfab",
"action.upload_sketchfab.desc": "Upload your model to Sketchfab",
"action.share_model": "Share...",
"action.share_model.desc": "Generate a short link to share your model",
"action.save_project": "Save Project",
"action.save_project.desc": "Saves the current model as a project file",