refactor(endpoints): keep Teams CDN and link proxy hosts in chatsvc
- new chatsvc::teams_cdn holds the statics.teams.cdn.office.net URLs for sounds, stickers, emoticons and backgrounds - app-base and calling read their CDN bases from it - core external_image reuses chatsvc::links::LINK_PROXY_HOST_SUFFIX for asyncgw Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -9,7 +9,7 @@ use teams_core::EmoticonTag;
9
9
pub use strip::{StripImages, StripLoader, StripSource, split_strip};
10
10
11
11
const CATALOG: &str = include_str!("../../../app/assets/emoticons.tsv");
12
const ASSET_BASE: &str = "https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons";
12
const ASSET_BASE: &str = chatsvc::teams_cdn::EMOTICON_BASE_URL;
13
13
const ASSET_SIZE: u32 = 100;
14
14
const FRAMES_PER_SECOND: u64 = 24;
15
15
const VARIATION_SELECTOR: char = '\u{fe0f}';
@@ -9,7 +9,7 @@ use teams_core::EmoticonTag;9
pub use strip::{StripImages, StripLoader, StripSource, split_strip};9
pub use strip::{StripImages, StripLoader, StripSource, split_strip};10
10
11
const CATALOG: &str = include_str!("../../../app/assets/emoticons.tsv");11
const CATALOG: &str = include_str!("../../../app/assets/emoticons.tsv");12
const ASSET_BASE: &str = "https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons";12
const ASSET_BASE: &str = chatsvc::teams_cdn::EMOTICON_BASE_URL;13
const ASSET_SIZE: u32 = 100;13
const ASSET_SIZE: u32 = 100;14
const FRAMES_PER_SECOND: u64 = 24;14
const FRAMES_PER_SECOND: u64 = 24;15
const VARIATION_SELECTOR: char = '\u{fe0f}';15
const VARIATION_SELECTOR: char = '\u{fe0f}';@@ -8,8 +8,7 @@ use gpui_kit::App;
8
8
9
9
use super::platform;
10
10
11
pub const TEAMS_SOUND_BASE_URL: &str =
12
"https://statics.teams.cdn.office.net/evergreen-assets/audio/";
11
pub const TEAMS_SOUND_BASE_URL: &str = chatsvc::teams_cdn::SOUND_BASE_URL;
13
12
const SOUND_DIRECTORY: &str = "sounds";
14
13
const PARTIAL_SUFFIX: &str = ".partial";
15
14
@@ -8,8 +8,7 @@ use gpui_kit::App;8
8
9
use super::platform;9
use super::platform;10
10
11
pub const TEAMS_SOUND_BASE_URL: &str =11
pub const TEAMS_SOUND_BASE_URL: &str = chatsvc::teams_cdn::SOUND_BASE_URL;12
"https://statics.teams.cdn.office.net/evergreen-assets/audio/";13
const SOUND_DIRECTORY: &str = "sounds";12
const SOUND_DIRECTORY: &str = "sounds";14
const PARTIAL_SUFFIX: &str = ".partial";13
const PARTIAL_SUFFIX: &str = ".partial";15
14
@@ -1,7 +1,7 @@
1
1
use std::sync::OnceLock;
2
2
3
3
const CATALOG: &str = include_str!("../../app/assets/stickers.tsv");
4
const IMAGE_BASE: &str = "https://statics.teams.cdn.office.net/evergreen-assets/stickerassets";
4
const IMAGE_BASE: &str = chatsvc::teams_cdn::STICKER_BASE_URL;
5
5
const IMAGE_VERSION: u32 = 5;
6
6
const POPULAR_IDS: [&str; 6] = [
7
7
"Clippy_HelloThere",
@@ -1,7 +1,7 @@1
use std::sync::OnceLock;1
use std::sync::OnceLock;2
2
3
const CATALOG: &str = include_str!("../../app/assets/stickers.tsv");3
const CATALOG: &str = include_str!("../../app/assets/stickers.tsv");4
const IMAGE_BASE: &str = "https://statics.teams.cdn.office.net/evergreen-assets/stickerassets";4
const IMAGE_BASE: &str = chatsvc::teams_cdn::STICKER_BASE_URL;5
const IMAGE_VERSION: u32 = 5;5
const IMAGE_VERSION: u32 = 5;6
const POPULAR_IDS: [&str; 6] = [6
const POPULAR_IDS: [&str; 6] = [7
"Clippy_HelloThere",7
"Clippy_HelloThere",@@ -6,8 +6,8 @@ use session::{Request, Scope, Session};
6
6
7
7
use crate::error::{Error, Result};
8
8
9
pub const CATALOG_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/backgroundimages/config.json?v=7";
10
pub const CDN_ROOT: &str = "https://statics.teams.cdn.office.net";
9
pub const CATALOG_URL: &str = chatsvc::teams_cdn::BACKGROUND_CATALOG_URL;
10
pub const CDN_ROOT: &str = chatsvc::teams_cdn::ROOT;
11
11
const FETCH_SCOPE: &str = "Chat.Read";
12
12
const MAX_SIDE: u32 = 1920;
13
13
const CATALOG_FILE: &str = "config.json";
@@ -6,8 +6,8 @@ use session::{Request, Scope, Session};6
6
7
use crate::error::{Error, Result};7
use crate::error::{Error, Result};8
8
9
pub const CATALOG_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/backgroundimages/config.json?v=7";9
pub const CATALOG_URL: &str = chatsvc::teams_cdn::BACKGROUND_CATALOG_URL;10
pub const CDN_ROOT: &str = "https://statics.teams.cdn.office.net";10
pub const CDN_ROOT: &str = chatsvc::teams_cdn::ROOT;11
const FETCH_SCOPE: &str = "Chat.Read";11
const FETCH_SCOPE: &str = "Chat.Read";12
const MAX_SIDE: u32 = 1920;12
const MAX_SIDE: u32 = 1920;13
const CATALOG_FILE: &str = "config.json";13
const CATALOG_FILE: &str = "config.json";@@ -27,6 +27,7 @@ pub mod settings;
27
27
pub mod sound_settings;
28
28
pub mod sounds;
29
29
pub mod substrate_search;
30
pub mod teams_cdn;
30
31
pub mod transcripts;
31
32
pub mod translate;
32
33
pub mod window;
@@ -27,6 +27,7 @@ pub mod settings;27
pub mod sound_settings;27
pub mod sound_settings;28
pub mod sounds;28
pub mod sounds;29
pub mod substrate_search;29
pub mod substrate_search;30
pub mod teams_cdn;30
pub mod transcripts;31
pub mod transcripts;31
pub mod translate;32
pub mod translate;32
pub mod window;33
pub mod window;@@ -7,7 +7,7 @@ use crate::error::{Error, Result};
7
7
use crate::messages::{ConversationRef, MessageTransport, Messages, encode, ensure_success};
8
8
9
9
const URLP_BASE: &str = "https://de-prod.asyncgw.teams.microsoft.com/urlp/v1/url";
10
const IMAGE_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";
10
pub const LINK_PROXY_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";
11
11
const LIST_VIEW: &str = "msnp24Equivalent";
12
12
13
13
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -36,7 +36,7 @@ pub struct LinkImage {
36
36
pub fn is_link_image_url(url: &str) -> bool {
37
37
url.strip_prefix("https://")
38
38
.and_then(|rest| rest.split(['/', '?', '#']).next())
39
.is_some_and(|host| host.ends_with(IMAGE_HOST_SUFFIX))
39
.is_some_and(|host| host.ends_with(LINK_PROXY_HOST_SUFFIX))
40
40
}
41
41
42
42
pub fn parse_message_links(body: &Value) -> Vec<MessageLinks> {
@@ -7,7 +7,7 @@ use crate::error::{Error, Result};7
use crate::messages::{ConversationRef, MessageTransport, Messages, encode, ensure_success};7
use crate::messages::{ConversationRef, MessageTransport, Messages, encode, ensure_success};8
8
9
const URLP_BASE: &str = "https://de-prod.asyncgw.teams.microsoft.com/urlp/v1/url";9
const URLP_BASE: &str = "https://de-prod.asyncgw.teams.microsoft.com/urlp/v1/url";10
const IMAGE_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";10
pub const LINK_PROXY_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";11
const LIST_VIEW: &str = "msnp24Equivalent";11
const LIST_VIEW: &str = "msnp24Equivalent";12
12
13
#[derive(Debug, Clone, PartialEq, Eq)]13
#[derive(Debug, Clone, PartialEq, Eq)]@@ -36,7 +36,7 @@ pub struct LinkImage {36
pub fn is_link_image_url(url: &str) -> bool {36
pub fn is_link_image_url(url: &str) -> bool {37
url.strip_prefix("https://")37
url.strip_prefix("https://")38
.and_then(|rest| rest.split(['/', '?', '#']).next())38
.and_then(|rest| rest.split(['/', '?', '#']).next())39
.is_some_and(|host| host.ends_with(IMAGE_HOST_SUFFIX))39
.is_some_and(|host| host.ends_with(LINK_PROXY_HOST_SUFFIX))40
}40
}41
41
42
pub fn parse_message_links(body: &Value) -> Vec<MessageLinks> {42
pub fn parse_message_links(body: &Value) -> Vec<MessageLinks> {@@ -0,0 +1,29 @@
1
pub const HOST: &str = "statics.teams.cdn.office.net";
2
pub const ROOT: &str = "https://statics.teams.cdn.office.net";
3
pub const SOUND_BASE_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/audio/";
4
pub const STICKER_BASE_URL: &str =
5
"https://statics.teams.cdn.office.net/evergreen-assets/stickerassets";
6
pub const EMOTICON_BASE_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons";
7
pub const BACKGROUND_CATALOG_URL: &str =
8
"https://statics.teams.cdn.office.net/evergreen-assets/backgroundimages/config.json?v=7";
9
10
#[cfg(test)]
11
mod tests {
12
use super::*;
13
14
#[test]
15
fn every_url_lives_on_the_cdn_root() {
16
assert_eq!(ROOT, format!("https://{HOST}"));
17
for url in [
18
SOUND_BASE_URL,
19
STICKER_BASE_URL,
20
EMOTICON_BASE_URL,
21
BACKGROUND_CATALOG_URL,
22
] {
23
assert!(
24
url.starts_with(&format!("{ROOT}/evergreen-assets/")),
25
"{url}"
26
);
27
}
28
}
29
}
@@ -0,0 +1,29 @@1
pub const HOST: &str = "statics.teams.cdn.office.net";2
pub const ROOT: &str = "https://statics.teams.cdn.office.net";3
pub const SOUND_BASE_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/audio/";4
pub const STICKER_BASE_URL: &str =5
"https://statics.teams.cdn.office.net/evergreen-assets/stickerassets";6
pub const EMOTICON_BASE_URL: &str = "https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons";7
pub const BACKGROUND_CATALOG_URL: &str =8
"https://statics.teams.cdn.office.net/evergreen-assets/backgroundimages/config.json?v=7";9
10
#[cfg(test)]11
mod tests {12
use super::*;13
14
#[test]15
fn every_url_lives_on_the_cdn_root() {16
assert_eq!(ROOT, format!("https://{HOST}"));17
for url in [18
SOUND_BASE_URL,19
STICKER_BASE_URL,20
EMOTICON_BASE_URL,21
BACKGROUND_CATALOG_URL,22
] {23
assert!(24
url.starts_with(&format!("{ROOT}/evergreen-assets/")),25
"{url}"26
);27
}28
}29
}@@ -1,9 +1,9 @@
1
1
use url::Url;
2
2
3
3
const PROXY_PATH: &str = "/urlp/v1/url/content";
4
const PROXY_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";
4
const PROXY_HOST_SUFFIX: &str = chatsvc::links::LINK_PROXY_HOST_SUFFIX;
5
5
const GIPHY_HOST: &str = "giphy.com";
6
const TEAMS_CDN_HOST: &str = "statics.teams.cdn.office.net";
6
const TEAMS_CDN_HOST: &str = chatsvc::teams_cdn::HOST;
7
7
8
8
/// The direct URL of a GIF or sticker image, `None` when `src` is not one of the known public hosts.
9
9
pub fn external_image_url(src: &str) -> Option<String> {
@@ -1,9 +1,9 @@1
use url::Url;1
use url::Url;2
2
3
const PROXY_PATH: &str = "/urlp/v1/url/content";3
const PROXY_PATH: &str = "/urlp/v1/url/content";4
const PROXY_HOST_SUFFIX: &str = ".asyncgw.teams.microsoft.com";4
const PROXY_HOST_SUFFIX: &str = chatsvc::links::LINK_PROXY_HOST_SUFFIX;5
const GIPHY_HOST: &str = "giphy.com";5
const GIPHY_HOST: &str = "giphy.com";6
const TEAMS_CDN_HOST: &str = "statics.teams.cdn.office.net";6
const TEAMS_CDN_HOST: &str = chatsvc::teams_cdn::HOST;7
7
8
/// The direct URL of a GIF or sticker image, `None` when `src` is not one of the known public hosts.8
/// The direct URL of a GIF or sticker image, `None` when `src` is not one of the known public hosts.9
pub fn external_image_url(src: &str) -> Option<String> {9
pub fn external_image_url(src: &str) -> Option<String> {