31 lines
916 B
JavaScript
31 lines
916 B
JavaScript
|
function makeAPI(root) {
|
||
|
const Attribute = root.lookupType("models.proto.cofd.api.Attribute");
|
||
|
|
||
|
const attributeResource = (username, characterID, attribute) =>
|
||
|
'/api/cofd/' + username + '/' + characterID + '/attribute/' + attribute;
|
||
|
|
||
|
async function updateAttribute(params) {
|
||
|
const { username, characterID, attribute, newValue } = params;
|
||
|
|
||
|
let req = Attribute.create({
|
||
|
name: attribute,
|
||
|
value: parseInt(newValue)
|
||
|
});
|
||
|
|
||
|
const resource = attributeResource(username, characterID, attribute);
|
||
|
|
||
|
let resp = await fetch(resource, {
|
||
|
method: 'POST',
|
||
|
body: Attribute.encode(req).finish()
|
||
|
}).then(async resp => {
|
||
|
console.log("resp is", await resp.text());
|
||
|
}).catch(async err => {
|
||
|
console.log("err is", err.text());
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
updateAttribute
|
||
|
};
|
||
|
}
|