mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-31 05:10:22 +00:00
use domains for relay data, path is fixed
This commit is contained in:
@@ -171,7 +171,7 @@ data ChatConfig = ChatConfig
|
||||
}
|
||||
|
||||
data WebPreviewConfig = WebPreviewConfig
|
||||
{ baseWebUrl :: Text,
|
||||
{ webDomain :: Text,
|
||||
webJsonDir :: FilePath,
|
||||
webCorsFile :: Maybe FilePath,
|
||||
webUpdateInterval :: Int -- seconds
|
||||
|
||||
@@ -4880,14 +4880,14 @@ runRelayGroupLinkChecks user = do
|
||||
sendRelayCapIfNeeded vr gInfo
|
||||
sendRelayCapIfNeeded vr gInfo = do
|
||||
ChatConfig {webPreviewConfig} <- asks config
|
||||
let currentWebUrl = (\WebPreviewConfig {baseWebUrl} -> baseWebUrl) <$> webPreviewConfig
|
||||
sentWebUrl <- withStore' (`getRelaySentWebUrl` gInfo)
|
||||
when (currentWebUrl /= sentWebUrl) $ do
|
||||
let currentWebDomain = (\WebPreviewConfig {webDomain} -> webDomain) <$> webPreviewConfig
|
||||
sentWebDomain <- withStore' (`getRelaySentWebDomain` gInfo)
|
||||
when (currentWebDomain /= sentWebDomain) $ do
|
||||
owners <- withStore' $ \db -> getGroupOwners db vr user gInfo
|
||||
let capableOwners = filter (\m -> memberCurrent m && m `supportsVersion` relayWebCapVersion) owners
|
||||
unless (null capableOwners) $ do
|
||||
void $ sendGroupMessage' user gInfo capableOwners (XGrpRelayCap RelayCapabilities {baseWebUrl = currentWebUrl})
|
||||
withStore' $ \db -> updateRelaySentWebUrl db gInfo currentWebUrl
|
||||
void $ sendGroupMessage' user gInfo capableOwners (XGrpRelayCap RelayCapabilities {webDomain = currentWebDomain})
|
||||
withStore' $ \db -> updateRelaySentWebDomain db gInfo currentWebDomain
|
||||
checkRelayInactiveGroups = do
|
||||
vr <- chatVersionRange
|
||||
ttl <- asks (relayInactiveTTL . config)
|
||||
|
||||
@@ -1046,8 +1046,8 @@ acceptRelayJoinRequestAsync
|
||||
cReqChatVRange
|
||||
relayLink = do
|
||||
ChatConfig {webPreviewConfig} <- asks config
|
||||
let webUrl = (\WebPreviewConfig {baseWebUrl} -> baseWebUrl) <$> webPreviewConfig
|
||||
msg = XGrpRelayAcpt relayLink RelayCapabilities {baseWebUrl = webUrl}
|
||||
let webDomain_ = (\WebPreviewConfig {webDomain} -> webDomain) <$> webPreviewConfig
|
||||
msg = XGrpRelayAcpt relayLink RelayCapabilities {webDomain = webDomain_}
|
||||
subMode <- chatReadVar subscriptionMode
|
||||
vr <- chatVersionRange
|
||||
let chatV = vr `peerConnChatVersion` cReqChatVRange
|
||||
|
||||
@@ -242,12 +242,12 @@ coreChatOptsP appDir defaultDbName = do
|
||||
<> help "Run as a chat relay client"
|
||||
)
|
||||
webPreviewConfig <- do
|
||||
baseWebUrl_ <-
|
||||
webDomain_ <-
|
||||
optional $
|
||||
strOption
|
||||
( long "relay-web-url"
|
||||
<> metavar "URL"
|
||||
<> help "Base URL for channel web previews (relay only)"
|
||||
( long "relay-web-domain"
|
||||
<> metavar "DOMAIN"
|
||||
<> help "Domain for channel web previews (relay only)"
|
||||
)
|
||||
webJsonDir_ <-
|
||||
optional $
|
||||
@@ -270,10 +270,10 @@ coreChatOptsP appDir defaultDbName = do
|
||||
<> help "Interval between web preview regeneration in seconds (relay only)"
|
||||
<> value 300
|
||||
)
|
||||
pure $ case (baseWebUrl_, webJsonDir_) of
|
||||
(Just baseWebUrl, Just webJsonDir) -> Just WebPreviewConfig {baseWebUrl, webJsonDir, webCorsFile, webUpdateInterval}
|
||||
pure $ case (webDomain_, webJsonDir_) of
|
||||
(Just webDomain, Just webJsonDir) -> Just WebPreviewConfig {webDomain, webJsonDir, webCorsFile, webUpdateInterval}
|
||||
(Nothing, Nothing) -> Nothing
|
||||
_ -> error "--relay-web-url and --relay-web-dir must both be provided"
|
||||
_ -> error "--relay-web-domain and --relay-web-dir must both be provided"
|
||||
highlyAvailable <-
|
||||
switch
|
||||
( long "ha"
|
||||
|
||||
@@ -99,8 +99,8 @@ module Simplex.Chat.Store.Groups
|
||||
createRelayRequestGroup,
|
||||
updateRelayOwnStatusFromTo,
|
||||
updateRelayOwnStatus_,
|
||||
getRelaySentWebUrl,
|
||||
updateRelaySentWebUrl,
|
||||
getRelaySentWebDomain,
|
||||
updateRelaySentWebDomain,
|
||||
isRelayGroupRejected,
|
||||
allowRelayGroup,
|
||||
getRelayServedGroups,
|
||||
@@ -1644,13 +1644,13 @@ updateRelayOwnStatus_ db GroupInfo {groupId} relayStatus = do
|
||||
let inactiveAt_ = if relayStatus == RSInactive then Just currentTs else Nothing
|
||||
DB.execute db "UPDATE groups SET relay_own_status = ?, relay_inactive_at = ?, updated_at = ? WHERE group_id = ?" (relayStatus, inactiveAt_, currentTs, groupId)
|
||||
|
||||
getRelaySentWebUrl :: DB.Connection -> GroupInfo -> IO (Maybe Text)
|
||||
getRelaySentWebUrl db GroupInfo {groupId} =
|
||||
join <$> maybeFirstRow fromOnly (DB.query db "SELECT relay_sent_web_url FROM groups WHERE group_id = ?" (Only groupId))
|
||||
getRelaySentWebDomain :: DB.Connection -> GroupInfo -> IO (Maybe Text)
|
||||
getRelaySentWebDomain db GroupInfo {groupId} =
|
||||
join <$> maybeFirstRow fromOnly (DB.query db "SELECT relay_sent_web_domain FROM groups WHERE group_id = ?" (Only groupId))
|
||||
|
||||
updateRelaySentWebUrl :: DB.Connection -> GroupInfo -> Maybe Text -> IO ()
|
||||
updateRelaySentWebUrl db GroupInfo {groupId} webUrl =
|
||||
DB.execute db "UPDATE groups SET relay_sent_web_url = ? WHERE group_id = ?" (webUrl, groupId)
|
||||
updateRelaySentWebDomain :: DB.Connection -> GroupInfo -> Maybe Text -> IO ()
|
||||
updateRelaySentWebDomain db GroupInfo {groupId} webDomain_ =
|
||||
DB.execute db "UPDATE groups SET relay_sent_web_domain = ? WHERE group_id = ?" (webDomain_, groupId)
|
||||
|
||||
-- Flip every RSRejected row sharing the targeted group's relay_request_group_link
|
||||
-- to RSInactive in one statement; returns the refreshed GroupInfo for the targeted groupId.
|
||||
|
||||
@@ -35,7 +35,7 @@ import Simplex.Chat.Store.Postgres.Migrations.M20260515_public_group_access
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20260529_delivery_job_senders
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20260530_client_services
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20260531_member_removed_at
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20260531_relay_sent_web_url
|
||||
import Simplex.Chat.Store.Postgres.Migrations.M20260531_relay_sent_web_domain
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Text, Maybe Text)]
|
||||
@@ -71,7 +71,7 @@ schemaMigrations =
|
||||
("20260529_delivery_job_senders", m20260529_delivery_job_senders, Just down_m20260529_delivery_job_senders),
|
||||
("20260530_client_services", m20260530_client_services, Just down_m20260530_client_services),
|
||||
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at),
|
||||
("20260531_relay_sent_web_url", m20260531_relay_sent_web_url, Just down_m20260531_relay_sent_web_url)
|
||||
("20260531_relay_sent_web_domain", m20260531_relay_sent_web_domain, Just down_m20260531_relay_sent_web_domain)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20260531_relay_sent_web_domain where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20260531_relay_sent_web_domain :: Text
|
||||
m20260531_relay_sent_web_domain =
|
||||
[r|
|
||||
ALTER TABLE groups ADD COLUMN relay_sent_web_domain TEXT;
|
||||
|]
|
||||
|
||||
down_m20260531_relay_sent_web_domain :: Text
|
||||
down_m20260531_relay_sent_web_domain =
|
||||
[r|
|
||||
ALTER TABLE groups DROP COLUMN relay_sent_web_domain;
|
||||
|]
|
||||
@@ -1,19 +0,0 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.Postgres.Migrations.M20260531_relay_sent_web_url where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
m20260531_relay_sent_web_url :: Text
|
||||
m20260531_relay_sent_web_url =
|
||||
[r|
|
||||
ALTER TABLE groups ADD COLUMN relay_sent_web_url TEXT;
|
||||
|]
|
||||
|
||||
down_m20260531_relay_sent_web_url :: Text
|
||||
down_m20260531_relay_sent_web_url =
|
||||
[r|
|
||||
ALTER TABLE groups DROP COLUMN relay_sent_web_url;
|
||||
|]
|
||||
@@ -158,7 +158,7 @@ import Simplex.Chat.Store.SQLite.Migrations.M20260515_public_group_access
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20260529_delivery_job_senders
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20260530_client_services
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20260531_member_removed_at
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20260531_relay_sent_web_url
|
||||
import Simplex.Chat.Store.SQLite.Migrations.M20260531_relay_sent_web_domain
|
||||
import Simplex.Messaging.Agent.Store.Shared (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Query, Maybe Query)]
|
||||
@@ -317,7 +317,7 @@ schemaMigrations =
|
||||
("20260529_delivery_job_senders", m20260529_delivery_job_senders, Just down_m20260529_delivery_job_senders),
|
||||
("20260530_client_services", m20260530_client_services, Just down_m20260530_client_services),
|
||||
("20260531_member_removed_at", m20260531_member_removed_at, Just down_m20260531_member_removed_at),
|
||||
("20260531_relay_sent_web_url", m20260531_relay_sent_web_url, Just down_m20260531_relay_sent_web_url)
|
||||
("20260531_relay_sent_web_domain", m20260531_relay_sent_web_domain, Just down_m20260531_relay_sent_web_domain)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20260531_relay_sent_web_domain where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20260531_relay_sent_web_domain :: Query
|
||||
m20260531_relay_sent_web_domain =
|
||||
[sql|
|
||||
ALTER TABLE groups ADD COLUMN relay_sent_web_domain TEXT;
|
||||
|]
|
||||
|
||||
down_m20260531_relay_sent_web_domain :: Query
|
||||
down_m20260531_relay_sent_web_domain =
|
||||
[sql|
|
||||
ALTER TABLE groups DROP COLUMN relay_sent_web_domain;
|
||||
|]
|
||||
@@ -1,18 +0,0 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.SQLite.Migrations.M20260531_relay_sent_web_url where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20260531_relay_sent_web_url :: Query
|
||||
m20260531_relay_sent_web_url =
|
||||
[sql|
|
||||
ALTER TABLE groups ADD COLUMN relay_sent_web_url TEXT;
|
||||
|]
|
||||
|
||||
down_m20260531_relay_sent_web_url :: Query
|
||||
down_m20260531_relay_sent_web_url =
|
||||
[sql|
|
||||
ALTER TABLE groups DROP COLUMN relay_sent_web_url;
|
||||
|]
|
||||
@@ -1206,8 +1206,8 @@ viewReceivedContactRequest c Profile {fullName, shortDescr} =
|
||||
]
|
||||
|
||||
showRelay :: GroupRelay -> StyledString
|
||||
showRelay GroupRelay {groupRelayId, relayStatus, relayCap = RelayCapabilities {baseWebUrl}} =
|
||||
" - relay id " <> sShow groupRelayId <> ": " <> plain (relayStatusText relayStatus) <> maybe "" (\url -> ", web: " <> plain url) baseWebUrl
|
||||
showRelay GroupRelay {groupRelayId, relayStatus, relayCap = RelayCapabilities {webDomain}} =
|
||||
" - relay id " <> sShow groupRelayId <> ": " <> plain (relayStatusText relayStatus) <> maybe "" (\d -> ", web: " <> plain d) webDomain
|
||||
|
||||
viewGroupRelays :: GroupInfo -> [GroupRelay] -> [StyledString]
|
||||
viewGroupRelays g relays =
|
||||
|
||||
@@ -227,6 +227,9 @@ corsEntry publicGroupId PublicGroupAccess {groupWebPage, allowEmbedding} =
|
||||
| otherwise = CorsOrigins []
|
||||
in (fName, origin)
|
||||
|
||||
channelPath :: Text
|
||||
channelPath = "/channel/"
|
||||
|
||||
writeCorsConfig :: [(Text, CorsOrigin)] -> FilePath -> IO ()
|
||||
writeCorsConfig entries path =
|
||||
TIO.writeFile path $ T.unlines $
|
||||
@@ -234,15 +237,15 @@ writeCorsConfig entries path =
|
||||
<> map corsLine entries
|
||||
<> [ " default \"\"",
|
||||
"}",
|
||||
"header /preview/*.json Access-Control-Allow-Origin {cors_origin}",
|
||||
"header /preview/*.json Access-Control-Allow-Methods \"GET, OPTIONS\""
|
||||
"header " <> channelPath <> "*.json Access-Control-Allow-Origin {cors_origin}",
|
||||
"header " <> channelPath <> "*.json Access-Control-Allow-Methods \"GET, OPTIONS\""
|
||||
]
|
||||
where
|
||||
corsLine (fName, origin) = case origin of
|
||||
CorsAny -> " /preview/" <> fName <> " \"*\""
|
||||
CorsAny -> " " <> channelPath <> fName <> " \"*\""
|
||||
CorsOrigins origins -> case origins of
|
||||
[] -> " # " <> fName <> " (no origin configured)"
|
||||
(o : _) -> " /preview/" <> fName <> " \"" <> o <> "\""
|
||||
(o : _) -> " " <> channelPath <> fName <> " \"" <> o <> "\""
|
||||
|
||||
publicGroupIdFileName :: B64UrlByteString -> String
|
||||
publicGroupIdFileName = B.unpack . strEncode
|
||||
|
||||
Reference in New Issue
Block a user