Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function (context, arg) {
- var uid = auth.parseAuthToken(arg.token).uid;
- var hash = arg.hash;
- var device_id = arg.device_id;
- let connection = await savedb.getConnection();
- try {
- let [hash_row] = await connection.execute("SELECT hash, device_id, ref FROM users WHERE uid=?", [uid]);
- if (hash_row && hash_row.length > 0) {
- let stored = hash_row[0];
- let stored_hash = stored.hash;
- if (hash == stored_hash) {
- return {
- status: "not_modified",
- device_id: stored.device_id,
- hash: stored_hash
- };
- } else if (stored.device_id == device_id) {
- return {
- status: "same_device",
- device_id: stored.device_id,
- hash: stored_hash
- };
- } else {
- let [[data]] = await connection.execute("SELECT data FROM blobs WHERE id=? AND hash=?", [stored.ref, stored.hash]);
- if ( data ) {
- return {
- status: "ok",
- data: data.data.toString(),
- device_id: stored.device_id,
- hash: stored_hash
- };
- } else {
- throw new j15.ApiError("corrupted_data", "Data for the user is either concurrently accessed, or corrupted");
- }
- }
- } else {
- return null;
- }
- } finally {
- connection.release();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement