11// Document handlers
22
33use anyhow:: Error as AnyError ;
4- use axum:: extract:: ws:: { Message , WebSocket , WebSocketUpgrade } ;
54use axum:: {
65 Json ,
76 body:: { Body , Bytes } ,
@@ -13,20 +12,16 @@ use axum::{
1312 response:: { IntoResponse , Response } ,
1413} ;
1514use barffine_core:: blob:: BlobDescriptor ;
16- use base64:: { Engine as _, engine:: general_purpose:: STANDARD as BASE64 } ;
17- use serde:: Deserialize ;
18- use tokio:: sync:: broadcast;
19- use tracing:: { error, warn} ;
2015use y_octo:: { Doc as YoctoDoc , StateVector as YoctoStateVector } ;
2116
2217use crate :: {
2318 auth:: { DocAccessIntent , RpcAccessRequirement , parse_history_timestamp, resolve_doc_access} ,
2419 doc:: {
25- channels:: { comment_attachment_blob_key, doc_channel_key } ,
20+ channels:: comment_attachment_blob_key,
2621 content:: { parse_doc_content, parse_doc_markdown} ,
2722 history, metadata as doc_metadata,
2823 mode:: DocPublishMode ,
29- sync:: { UpdateBroadcastContext , apply_doc_updates , workspace_snapshot_or_not_found} ,
24+ sync:: workspace_snapshot_or_not_found,
3025 } ,
3126 error:: AppError ,
3227 handlers:: headers:: {
@@ -35,8 +30,7 @@ use crate::{
3530 } ,
3631 handlers:: workspace_handlers:: ensure_workspace_exists,
3732 http:: { append_set_cookie_headers, http_date_from_datetime} ,
38- socket:: rooms:: SpaceType ,
39- state:: { AppState , SyncEventKind } ,
33+ state:: AppState ,
4034 types:: {
4135 AuthenticatedRestSession , DocContentQuery , DocContentResponse , DocMarkdownResponse ,
4236 DocumentHistoryItem , DocumentMetadataResponse , HistoryQuery , PublishDocRequest ,
@@ -46,9 +40,29 @@ use crate::{
4640 attachments:: apply_attachment_headers,
4741 crdt:: { decode_state_vector, encode_state_vector} ,
4842 } ,
49- workspace:: service:: { AccessTokenContext , AccessTokenVerification } ,
5043} ;
5144
45+ #[ cfg( feature = "legacy-doc-service" ) ]
46+ use axum:: extract:: ws:: { Message , WebSocket , WebSocketUpgrade } ;
47+ #[ cfg( feature = "legacy-doc-service" ) ]
48+ use base64:: { Engine as _, engine:: general_purpose:: STANDARD as BASE64 } ;
49+ #[ cfg( feature = "legacy-doc-service" ) ]
50+ use tokio:: sync:: broadcast;
51+ #[ cfg( feature = "legacy-doc-service" ) ]
52+ use crate :: state:: SyncEventKind ;
53+ #[ cfg( feature = "legacy-doc-service" ) ]
54+ use crate :: doc:: channels:: doc_channel_key;
55+ #[ cfg( feature = "legacy-doc-service" ) ]
56+ use crate :: doc:: sync:: { UpdateBroadcastContext , apply_doc_updates} ;
57+ #[ cfg( feature = "legacy-doc-service" ) ]
58+ use crate :: socket:: rooms:: SpaceType ;
59+ #[ cfg( feature = "legacy-doc-service" ) ]
60+ use crate :: workspace:: service:: { AccessTokenContext , AccessTokenVerification } ;
61+ #[ cfg( feature = "legacy-doc-service" ) ]
62+ use tracing:: { error, warn} ;
63+ #[ cfg( feature = "legacy-doc-service" ) ]
64+ use serde:: Deserialize ;
65+
5266pub ( crate ) async fn get_doc_content_handler (
5367 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
5468 State ( state) : State < AppState > ,
@@ -58,6 +72,7 @@ pub(crate) async fn get_doc_content_handler(
5872 Ok ( Json ( response) )
5973}
6074
75+ #[ cfg( feature = "legacy-doc-service" ) ]
6176pub ( crate ) async fn get_rpc_doc_content_handler (
6277 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
6378 State ( state) : State < AppState > ,
@@ -154,6 +169,7 @@ pub(crate) async fn get_doc_markdown_handler(
154169 Ok ( Json ( response) )
155170}
156171
172+ #[ cfg( feature = "legacy-doc-service" ) ]
157173pub ( crate ) async fn get_rpc_doc_markdown_handler (
158174 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
159175 State ( state) : State < AppState > ,
@@ -182,6 +198,7 @@ pub(crate) async fn get_doc_diff_handler(
182198 . await
183199}
184200
201+ #[ cfg( feature = "legacy-doc-service" ) ]
185202pub ( crate ) async fn get_rpc_doc_diff_handler (
186203 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
187204 State ( state) : State < AppState > ,
@@ -216,6 +233,7 @@ pub(crate) async fn get_doc_binary_handler(
216233 . await
217234}
218235
236+ #[ cfg( feature = "legacy-doc-service" ) ]
219237pub ( crate ) async fn get_rpc_doc_binary_handler (
220238 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
221239 State ( state) : State < AppState > ,
@@ -478,6 +496,7 @@ async fn doc_diff_response(
478496 Ok ( response)
479497}
480498
499+ #[ cfg( feature = "legacy-doc-service" ) ]
481500fn require_rpc_doc_token (
482501 state : & AppState ,
483502 headers : & HeaderMap ,
@@ -597,6 +616,7 @@ where
597616 Ok ( auth)
598617}
599618
619+ #[ cfg( feature = "legacy-doc-service" ) ]
600620pub ( crate ) async fn doc_ws_handler (
601621 ws : WebSocketUpgrade ,
602622 Path ( ( workspace_id, doc_id) ) : Path < ( String , String ) > ,
@@ -609,6 +629,7 @@ pub(crate) async fn doc_ws_handler(
609629 } )
610630}
611631
632+ #[ cfg( feature = "legacy-doc-service" ) ]
612633async fn handle_doc_websocket (
613634 mut socket : WebSocket ,
614635 state : AppState ,
@@ -750,6 +771,7 @@ pub(crate) async fn unpublish_doc_handler(
750771 Ok ( response)
751772}
752773
774+ #[ cfg( feature = "legacy-doc-service" ) ]
753775async fn process_incoming_ws_message (
754776 state : & AppState ,
755777 workspace_id : & str ,
0 commit comments