revoltchat / self-hosted

Deploy Revolt using Docker.
904 stars 116 forks source link

bug: revolt api doesn't proccess website embeds #78

Open account0123 opened 6 months ago

account0123 commented 6 months ago

What happened?

Context: I'm using remote self-host actually, I have replaced environment values to my actual public URLs. For example, JANUARY_PUBLIC_URL=http://PUBLIC_IP/january. Also connecting to http://PUBLIC_IP/january?embed=TENOR_URL from local machine works as expected.

Issue: When I send a message including TENOR_URL through api outputs

 INFO  rocket::server                                                   > POST /channels/01HRXJ97SMTM0JKJ956ZZHWS9Q/messages application/json:
 INFO  _                                                                > Matched: (message_send) POST /channels/<target>/messages
 INFO  revolt_database::tasks::last_message_id                          > Queue is using 1 slots from 10000.
 INFO  revolt_database::tasks::process_embeds                           > Queue is using 0 slots from 10000.
 WARN  isahc::handler                                                   > request completed with error: failed to connect to the server
 INFO  _                                                                > Outcome: Success
 INFO  _                                                                > Response succeeded.

Then I have looked up in backend source code and I realized the request handler is trying to make a request to complete process embed task.

# crates/quark/src/tasks/process_embeds.rs#L50
let embeds = Embed::generate(task.content, &JANUARY_URL, *MAX_EMBED_COUNT, semaphore).await;
# crates/core/database/src/tasks/process_embeds.rs#L85
if let Ok(mut response) = isahc::get_async(format!(
                "{host}/embed?url={}",
                url_escape::encode_component(&link)
            ))

Expected: Request should be completed, then embed is processed as website embed appended to message object.

insertish commented 6 months ago

More information is needed, if possible a full error (if you're willing to run a custom january in your stack to test this out) Seems like the API server just can't reach january for whatever reason?

account0123 commented 6 months ago

I made a local reproduction: TL;DR: Same issue but in local hosting.

  1. I cloned latest version of this repo (branch master). Then, the backend tags are latest according to last commit.
  2. Manually fixed a little issue about curl is not a command in createbuckets service. (Otherwise autumn does not run)
  3. I ran the stack.
  4. After creating a account on local.revolt.chat, I created a saved notes channel.
  5. I posted a message including a remote link messagewithlink
  6. Attached console outputs
    api-1            |  INFO  rocket::server                                                   > POST /channels/01HT6SDNTQSKCHDG8QG3FBDE7D/messages application/json:
    api-1            |  INFO  _                                                                > Matched: (message_send) POST /channels/<target>/messages
    api-1            |  INFO  revolt_database::tasks::last_message_id                          > Queue is using 1 slots from 10000.
    api-1            |  INFO  revolt_database::tasks::process_embeds                           > Queue is using 1 slots from 10000.
    api-1            |  INFO  _                                                                > Outcome: Success
    api-1            |  INFO  _                                                                > Response succeeded.
    api-1            |  WARN  isahc::handler                                                   > request completed with error: failed to connect to the server
    database-1       | {"t":{"$date":"2024-03-30T04:37:43.158+00:00"},"s":"I",  "c":"WRITE",    "id":51803,   "ctx":"conn8","msg":"Slow query","attr":{"type":"update","ns":"revolt.channels","command":{"q":{"_id":"01HT6SDNTQSKCHDG8QG3FBDE7D"},"u":{"$unset":{},"$set":{"last_message_id":"01HT6TC6FFC9MMBVMZ4MMEVQRG"}},"multi":false,"upsert":false},"planSummary":"IDHACK","keysExamined":1,"docsExamined":1,"nMatched":1,"nModified":1,"nUpserted":0,"keysInserted":0,"keysDeleted":0,"numYields":1,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":2}},"FeatureCompatibilityVersion":{"acquireCount":{"w":2}},"ReplicationStateTransition":{"acquireCount":{"w":2}},"Global":{"acquireCount":{"w":2}},"Database":{"acquireCount":{"w":2}},"Collection":{"acquireCount":{"w":2}}},"flowControl":{"acquireCount":2},"storage":{},"cpuNanos":1003176,"rem
    ![messagewithlink](https://github.com/revoltchat/self-hosted/assets/27470405/449ef41d-9fd7-4a86-8338-f35d5896dab5)
    ote":"172.19.0.9:43168","durationMillis":102}}
    database-1       | {"t":{"$date":"2024-03-30T04:37:43.158+00:00"},"s":"I",  "c":"COMMAND",  "id":51803,   "ctx":"conn8","msg":"Slow query","attr":{"type":"command","ns":"revolt.$cmd","command":{"update":"channels","updates":[{"q":{"_id":"01HT6SDNTQSKCHDG8QG3FBDE7D"},"u":{"$unset":{},"$set":{"last_message_id":"01HT6TC6FFC9MMBVMZ4MMEVQRG"}}}],"ordered":true,"$db":"revolt","lsid":{"id":{"$uuid":"19e3ab82-1eec-489b-828d-82c33ecf5def"}}},"numYields":1,"reslen":60,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":2}},"FeatureCompatibilityVersion":{"acquireCount":{"r":1,"w":2}},"ReplicationStateTransition":{"acquireCount":{"w":2}},"Global":{"acquireCount":{"r":1,"w":2}},"Database":{"acquireCount":{"w":2}},"Collection":{"acquireCount":{"w":2}}},"flowControl":{"acquireCount":2},"storage":{},"cpuNanos":1307368,"remote":"172.19.0.9:43168","protocol":"op_msg","durationMillis":103}}
    api-1            |  INFO  revolt_database::tasks::last_message_id                          > Updated last_message_id for 01HT6SDNTQSKCHDG8QG3FBDE7D to 01HT6TC6FFC9MMBVMZ4MMEVQRG.
  7. I manually inserted the following url http://local.revolt.chat/january/embed?url=http://autumn.revolt.chat/attachments/6K1y3HpD7rv_yUxge1Hs6heGmWj_PWsa-TqJTXpm0I Result:
    {"type":"Image","url":"http://autumn.revolt.chat/attachments/6K1y3HpD7rv_yUxge1Hs6heGmWj_PWsa-TqJTXpm0I","width":512,"height":512,"size":"Large"}
evilbulgarian commented 6 months ago

Yeah I am seeing the same issue, reverting delta to version 20230704-1 seems to work but only for youtube url's others still missing the metadata.