naturalcrit / homebrewery

Create authentic looking D&D homebrews using only markdown
https://homebrewery.naturalcrit.com
MIT License
1.07k stars 327 forks source link

Restoring trashed Google Drive file has potential for duplicate ID conflict #2099

Open calculuschild opened 2 years ago

calculuschild commented 2 years ago

Due to the change in #2089 to persist shareID and editID between Google Drive transfers. Since we don't fully delete the transferred file from the user's Google drive, but just send it to the Trash (in case it was accidental), recovering that file and then attempting to also send it to the Homebrewery will naturally result in a conflict in a duplicate ID.

However, this error manifests as the "Your google credentials are expired" popup. Simply providing a correct error message might be all we need to do here. The chance of this happening is pretty small I think.

Relevant server error:

MongoServerError: E11000 duplicate key error collection: homebrewery.homebrews index: shareId_1 dup key: { shareId: "eqnUtZ6a95aa" }
    at C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\operations\insert.js:51:33
    at C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\connection_pool.js:273:25
    at handleOperationResult (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\sdam\server.js:363:9)
    at MessageStream.messageHandler (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\connection.js:474:9)
    at MessageStream.emit (node:events:390:28)
    at processIncomingData (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
    at MessageStream._write (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at MessageStream.Writable.write (node:internal/streams/writable:334:10) {
  index: 0,
  code: 11000,
  keyPattern: { shareId: 1 },
  keyValue: { shareId: 'eqnUtZ6a95aa' }MongoServerError: E11000 duplicate key error collection: homebrewery.homebrews index: shareId_1 dup key: { shareId: "eqnUtZ6a95aa" }
    at C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\operations\insert.js:51:33
    at C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\connection_pool.js:273:25
    at handleOperationResult (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\sdam\server.js:363:9)
    at MessageStream.messageHandler (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\connection.js:474:9)
    at MessageStream.emit (node:events:390:28)
    at processIncomingData (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
    at MessageStream._write (C:\Users\Trevor\Documents\GitHub\homebrewery\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at MessageStream.Writable.write (node:internal/streams/writable:334:10) {
  index: 0,
  code: 11000,
  keyPattern: { shareId: 1 },
  keyValue: { shareId: 'eqnUtZ6a95aa' }
5e-Cleric commented 1 month ago

Trashed brews are viewable in the tool, with a popup showing that they are in the trash, is this still an issue?

calculuschild commented 1 month ago

That is a separate issue.

This issue is the possibility of having two brews with the same share and edit id (not sure if still exists, but should test): 1) Create a brew linked to a Google Drive 2) Transfer the brew to HB. The original Google Drive file is moved to Google Drive trash 3) Open Google Drive trash. Find the deleted file and restore it 4) Open user brews page. You now have two files with the same shareId, one on HB and one from Google Drive 5) Attempt to transfer the Google Drive file to HB 6) Error. Duplicate file ID.