<commit_before>import xhr from 'xhr';

const getBackpackContents = ({
    host,
    username,
    token,
    limit,
    offset
}) => new Promise((resolve, reject) => {
    xhr({
        method: 'GET',
        uri: `${host}${username}?limit=${limit}&offset=${offset}`,
        headers: {'x-token': token},
        json: true
    }, (error, response) => {
        if (error || response.statusCode !== 200) {
            return reject();
        }
        // Add a new property for the full thumbnail url, which includes the host.
        // TODO retreiving the images through storage would allow us to remove this.
        return resolve(response.body.map(item => (
            Object.assign({}, item, {thumbnailUrl: `${host}/${item.thumbnail}`})
        )));
    });
});

export {
    getBackpackContents
};
<commit_msg>Create API method for saving a backpack object<commit_after>import xhr from 'xhr';
import costumePayload from './backpack/costume-payload';
import soundPayload from './backpack/sound-payload';

const getBackpackContents = ({
    host,
    username,
    token,
    limit,
    offset
}) => new Promise((resolve, reject) => {
    xhr({
        method: 'GET',
        uri: `${host}${username}?limit=${limit}&offset=${offset}`,
        headers: {'x-token': token},
        json: true
    }, (error, response) => {
        if (error || response.statusCode !== 200) {
            return reject();
        }
        // Add a new property for the full thumbnail url, which includes the host.
        // TODO retreiving the images through storage would allow us to remove this.
        return resolve(response.body.map(item => (
            Object.assign({}, item, {thumbnailUrl: `${host}/${item.thumbnail}`})
        )));
    });
});

const saveBackpackObject = ({
    host,
    username,
    token,
    type, // Type of object being saved to the backpack
    mime, // Mime-type of the object being saved
    name, // User-facing name of the object being saved
    body, // Base64-encoded body of the object being saved
    thumbnail // Base64-encoded JPEG thumbnail of the object being saved
}) => new Promise((resolve, reject) => {
    xhr({
        method: 'POST',
        uri: `${host}${username}`,
        headers: {'x-token': token},
        json: {type, mime, name, body, thumbnail}
    }, (error, response) => {
        if (error || response.statusCode !== 200) {
            return reject();
        }
        return resolve(response.body);
    });
});

export {
    getBackpackContents,
    saveBackpackObject,
    costumePayload,
    soundPayload
};

{'fraction_non_alphanumeric': 0.14313496693893427, 'fraction_numerical': 0.005056398288603656, 'mean_word_length': 2.447721179624665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3359762', 'n_tokens_mistral': 733, 'n_tokens_neox': 725, 'n_words': 221}