SHARE
TWEET

Untitled

tinyevil Feb 19th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function (context, arg) {
  2.     var uid = auth.parseAuthToken(arg.token).uid;
  3.     var hash = arg.hash;
  4.     var device_id = arg.device_id;
  5.  
  6.     let connection = await savedb.getConnection();
  7.     try {
  8.         let [hash_row] = await connection.execute("SELECT hash, device_id, ref FROM users WHERE uid=?", [uid]);
  9.  
  10.         if (hash_row && hash_row.length > 0) {
  11.             let stored = hash_row[0];
  12.             let stored_hash = stored.hash;
  13.             if (hash == stored_hash) {
  14.                 return {
  15.                     status: "not_modified",
  16.                     device_id: stored.device_id,
  17.                     hash: stored_hash
  18.                 };
  19.             } else if (stored.device_id == device_id) {
  20.                 return {
  21.                     status: "same_device",
  22.                     device_id: stored.device_id,
  23.                     hash: stored_hash
  24.                 };
  25.             } else {
  26.                 let [[data]] = await connection.execute("SELECT data FROM blobs WHERE id=? AND hash=?", [stored.ref, stored.hash]);
  27.                 if ( data ) {
  28.                     return {
  29.                         status: "ok",
  30.                         data: data.data.toString(),
  31.                         device_id: stored.device_id,
  32.                         hash: stored_hash
  33.                     };
  34.                 } else {
  35.                     throw new j15.ApiError("corrupted_data", "Data for the user is either concurrently accessed, or corrupted");
  36.                 }
  37.             }
  38.         } else {
  39.             return null;
  40.         }
  41.     } finally {
  42.         connection.release();
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top