-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgallery-loader.xml
1 lines (1 loc) · 4.95 KB
/
gallery-loader.xml
1
<blocks app="NetsBlox 1.14.0, http://netsblox.org" version="1.14.0"><block-definition collabId="item_0_61" s="Upload Work To Gallery" type="command" category="other"><header></header><code></code><inputs></inputs><script><block collabId="item_0_56" s="doDeclareVariables"><list><l>name</l><l>description</l></list></block><block collabId="item_0_52" s="doIf"><block collabId="item_0_51" s="reportLessThan"><block collabId="item_0_50" s="reportStringSize"><block collabId="item_0_49" var="name"/></block><l>2</l><comment collabId="item_0_47" w="159" collapsed="false">See if you can tell what this does...</comment></block><script><block collabId="item_0_45" s="doAsk"><l>Choose a Name or Identifier...</l></block><block collabId="item_0_43" s="doSetVar"><l>name</l><block collabId="item_0_41" s="getLastAnswer"></block></block></script></block><block collabId="item_0_40" s="doIf"><block collabId="item_0_39" s="reportLessThan"><block collabId="item_0_38" s="reportStringSize"><block collabId="item_0_37" var="description"/></block><l>2</l></block><script><block collabId="item_0_34" s="doAsk"><l>Describe your work briefly</l></block><block collabId="item_0_32" s="doSetVar"><l>description</l><block collabId="item_0_30" s="getLastAnswer"></block></block></script></block><block collabId="item_0_29" s="doIfElse"><block collabId="item_0_28" s="reportOr"><block collabId="item_0_27" s="reportLessThan"><block collabId="item_0_26" s="reportStringSize"><block collabId="item_0_25" var="name"/></block><l>2</l><comment collabId="item_0_23" w="159" collapsed="false">See if you can tell what this does...</comment></block><block collabId="item_0_22" s="reportLessThan"><block collabId="item_0_21" s="reportStringSize"><block collabId="item_0_20" var="description"/></block><l>2</l></block></block><script><block collabId="item_0_17" s="doSayFor"><l>Canceled Upload. Need name and description to be more than 2 chars</l><l>2</l></block></script><script><block collabId="item_0_13" s="doReport"><block collabId="item_0_12" s="evaluate"><block collabId="item_0_11" s="reportJSFunction"><list><l>username</l><l>description</l><l>proc</l></list><l>let config = window.galleryConfig || {};
let stage = this.parentThatIsA(IDE_Morph).stage;
let image = new Costume(stage.thumbnail(stage.dimensions)).contents.toDataURL('image/png');

let nbm = window.world.children.find((x) => x instanceof NetsBloxMorph);
let data = nbm.serializer.format('<room name="@" app="@">%</room>', nbm.room.name, nbm.serializer.app, nbm.getSerializedRole());

let headers = {};
let method = "POST"
let bundle = {
 'data': data
, 'image': image
, 'metadata': JSON.stringify(Object.assign({ description: config.description || description, uploader: config.username || username }, (Object.keys(config).length > 0) ? { featured: true } : {}))
, 'session-id': window.externalVariables.locationHash
};

let makeEntriesFromFormData = function(obj, formData) {
 for (let key in (obj || {})) {
 formData.set(key, obj[key]);
 }
 return formData.entries();
};

let makeEntriesShim = function(obj, formElem) {

 let entryMap = new Map()

 if (formElem !== undefined) {
 Array.from(formElem.querySelectorAll("input[name]")).forEach((elem) => entryMap.set(elem.name, elem.value));
 }

 for (let key in (obj || {})) {
 entryMap.set(key, obj[key]);
 }

 return Array.from(entryMap.entries());

}

let makeQueryString = function(obj, formElem) {
 let removeCRs = (str) => str.replace(/\r/g, '');
 let formData = new FormData(formElem);
 let entries = (formData.entries !== undefined) ? makeEntriesFromFormData(obj, formData) : makeEntriesShim(obj, formElem);
 return Array.from(entries).map(([k, v]) => encodeURIComponent(k) + "=" + encodeURIComponent(removeCRs(v))).join("&");
}

var output;

if (!proc.promise) {
 proc.promise = new Promise(function() {
 var props = { method: method, headers: Object.assign({}, { "Content-Type": "application/x-www-form-urlencoded" }, headers) };
 if (method !== "GET") {
 let params = makeQueryString(bundle);
 props = Object.assign({}, props, { body: params });
 }
 fetch(window.externalVariables.domain + "/uploads", props);
 }).then(function(response) {
 response.text().then(function(body) { output = body; });
 });
} else {
 proc.promise = undefined;
 return output;
}

proc.pushContext('doYield');
proc.pushContext();
</l></block><list><block collabId="item_0_4" var="name"/><block collabId="item_0_3" var="description"/></list></block></block></script></block></script><scripts><script x="628.0000009999999" y="1636.8333343333331"><block collabId="item_0" s="errorObsolete"></block></script></scripts></block-definition></blocks>