Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: During upgrade i get some errors #119

Open
0ktav1us opened this issue Dec 24, 2024 · 7 comments
Open

bug: During upgrade i get some errors #119

0ktav1us opened this issue Dec 24, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@0ktav1us
Copy link

What happened?

hello, please help me finish updrad#84
run the migration: get error

root@1a7e78fdf5bb:/cwd# node ./20240929-autumn-rewrite.mjs 
1 7505 {
  _id: 'o4U--LPqcFkm6NpvCufKn1cmSZbMTUxwQX_qZ7gwDo',
  tag: 'attachments',
  filename: '2023-03-28 12-26-05.mkv',
  metadata: { type: 'File' },
  content_type: 'application/x-matroska',
  size: 1760809,
  message_id: '01GWKW2YNZ1M9DQP66414MH8S6'
}
file:///cwd/20240929-autumn-rewrite.mjs:41
    if (!objectLookup[f.message_id]) {
    ^

ReferenceError: objectLookup is not defined
    at determineUploaderIdAndUse (file:///cwd/20240929-autumn-rewrite.mjs:41:5)
    at file:///cwd/20240929-autumn-rewrite.mjs:347:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.7.3

And if I continue and run containers, I don't see attachments, it says that the files don't exist test

@0ktav1us 0ktav1us added the bug Something isn't working label Dec 24, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Untriaged in Revolt Project Dec 24, 2024
@0ktav1us
Copy link
Author

new images attach and display

@ThomasBaruzier
Copy link

Same behavior, here's what allowed me to finish the migration:

diff --git a/migrations/20240929-autumn-rewrite.mjs b/migrations/20240929-autumn-rewrite.mjs
index c8643bc..1ab854a 100644
--- a/migrations/20240929-autumn-rewrite.mjs
+++ b/migrations/20240929-autumn-rewrite.mjs
@@ -26,12 +26,38 @@ const BUCKET_MAP = {
  *
  * TODO: change if necessary
  */
-const CONNECTION_URL = "mongodb://database";
+const CONNECTION_URL = "mongodb://database:27017";
 
 const mongo = new MongoClient(CONNECTION_URL);
 await mongo.connect();
 
+const objectLookup = {};
+
+/**
+ * Decode timestamp from Ulid
+ * @param {string} id Ulid string
+ * @returns {number} Timestamp in milliseconds
+ */
+function decodeTime(id) {
+  // First 10 characters of ULID represent milliseconds precision timestamp
+  const timestamp = id.substring(0, 10);
+  // Convert from base32 to decimal
+  const base32Chars = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
+  let decoded = 0;
+  for (let i = 0; i < timestamp.length; i++) {
+    const char = timestamp[i];
+    const value = base32Chars.indexOf(char.toUpperCase());
+    if (value === -1) {
+      throw new Error(`Invalid ULID character: ${char}`);
+    }
+    decoded = decoded * 32 + value;
+  }
+  // ULID timestamps are in milliseconds
+  return decoded;
+}
+
 async function determineUploaderIdAndUse(f, v, i) {
+  console.log(`Processing file ${i}:`, f._id);
   if (f.tag === "attachments" && v === "attachments") {
     if (typeof f.message_id !== "string") {
       console.warn(i, "No message id specified.");
@@ -39,6 +65,7 @@ async function determineUploaderIdAndUse(f, v, i) {
     }
 
     if (!objectLookup[f.message_id]) {
+      console.log(`Querying database for message ${f.message_id}`);
       objectLookup[f.message_id] = await mongo
         .db("revolt")
         .collection("messages")
@@ -52,6 +79,7 @@ async function determineUploaderIdAndUse(f, v, i) {
       return null;
     }
 
+    console.log(`Found message ${f.message_id} for file ${f._id}`);
     return {
       uploaded_at: new Date(decodeTime(f.message_id)),
       uploader_id: objectLookup[f.message_id].author,
@@ -368,6 +396,7 @@ const files_pt2 = await mongo
   })
   .toArray();
 
+if (files_pt2.length > 0) {
 await mongo
   .db("revolt")
   .collection("attachment_hashes")
@@ -403,3 +432,10 @@ for (const file of files_pt2) {
       }
     );
 }
+} else {
+  console.log("No files to process in files_pt2.");
+}
+
+await mongo.close();
+console.log("Migration completed successfully.");
+process.exit(0);

And while the autumn server base URL responds with {"autumn":"Hello, I am a file server!","version":"0.8.1"}, my assets are still not found:

Image

@0ktav1us
Copy link
Author

0ktav1us commented Jan 20, 2025

Image
It worked, thanks, but I get the same error
{"type":"NotFound","location":"crates/services/autumn/src/api.rs:372:20"}

@ThomasBaruzier
Copy link

ThomasBaruzier commented Jan 20, 2025

It worked, thanks, but I get the same error {"type":"NotFound","location":"crates/services/autumn/src/api.rs:372:20"}

Well, we're in this together. I'll see what I can do soon enough but i'm pretty sure it's out of my reach.

@0ktav1us
Copy link
Author

Image
// Ignore files that haven't been attached,
According to this condition we get an error

@0ktav1us
Copy link
Author

I think we need to compare this piece of code with the old autumn, see how the attachments worked in the old one

@ThomasBaruzier
Copy link

In my opinion, the migration is not doing its job properly because of my manual dirty fix, hence the missing of attachment retrieval and this error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🆕 Untriaged
Development

No branches or pull requests

2 participants