1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#![allow(non_snake_case)]
use crate::AccountNumber;
#[allow(dead_code)]
type SitesContentKey = (AccountNumber, String);
/// Decompress content
///
/// `DecompressorInterface` is implemented by services that can decompress content
/// with a specific encoding.
///
/// Decompressor services should not inherit from this struct,
/// instead they should define actions with matching signatures.
///
/// The `sites` service uses decompressor services who implement this interface to
/// decompress content when the client's accepted encodings do not include the
/// content's encoding.
#[allow(dead_code)]
struct DecompressorInterface;
impl DecompressorInterface {
/// Decompresses content compressed with some algorithm
#[allow(dead_code, unused_variables)]
fn decompress(content: Vec<u8>) -> Vec<u8> {
unimplemented!()
}
}
#[crate::service(name = "sites", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
pub mod service {
use crate::fracpack::{Pack, ToSchema, Unpack};
use crate::{http::HttpRequest, AccountNumber, Checksum256, Hex};
use async_graphql::SimpleObject;
use serde::{Deserialize, Serialize};
#[table(name = "SitesContentTable", index = 0)]
#[derive(Debug, Clone, Serialize, Deserialize, SimpleObject, ToSchema, Pack, Unpack)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct SitesContentRow {
pub account: AccountNumber,
pub path: String,
pub contentType: String,
pub contentHash: Checksum256,
pub contentEncoding: Option<String>,
pub csp: Option<String>,
}
impl SitesContentRow {
#[primary_key]
fn pk(&self) -> (AccountNumber, String) {
(self.account, self.path.clone())
}
}
#[table(name = "SiteConfigTable", index = 1)]
#[derive(Debug, Clone, Serialize, Deserialize, SimpleObject, ToSchema, Pack, Unpack)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct SiteConfigRow {
#[primary_key]
pub account: AccountNumber,
pub spa: bool,
pub cache: bool,
pub globalCsp: Option<String>,
pub proxyAccount: Option<AccountNumber>,
}
#[table(name = "SitesDataTable", index = 2)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Pack, Unpack)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct SitesDataRow {
#[primary_key]
pub hash: Checksum256,
pub data: Vec<u8>,
}
#[table(name = "SitesDataRefTable", index = 3)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Pack, Unpack)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct SitesDataRefRow {
#[primary_key]
pub hash: Checksum256,
pub refs: u32,
}
/// Serves a request by looking up the content uploaded to the specified subdomain
#[action]
fn serveSys(request: HttpRequest) -> Option<crate::http::HttpReply> {
unimplemented!()
}
/// Stores content accessible at the caller's subdomain
#[action]
fn storeSys(
path: String,
contentType: String,
contentEncoding: Option<String>,
content: Hex<Vec<u8>>,
) {
unimplemented!()
}
/// Stores content accessible at the caller's subdomain
#[action]
fn hardlink(
path: String,
contentType: String,
contentEncoding: Option<String>,
contentHash: Checksum256,
) {
unimplemented!()
}
/// Removes content from the caller's subdomain
#[action]
fn remove(path: String) {
unimplemented!()
}
/// Checks whether a request for content on a site at the given path is valid (such a request will not produce a 404).
///
/// Note: For single-page applications, static assets (e.g. 'style.css') can be checked normally. However, all other assets
/// are routed client-side, so a route like `/page1` is considered a valid route as long as the SPA serves a root document.
#[action]
fn isValidPath(site: crate::AccountNumber, path: String) -> bool {
unimplemented!()
}
/// Enables/disables single-page application mode.
/// When enabled, all content requests return the root document.
#[action]
fn enableSpa(enable: bool) {
unimplemented!()
}
/// Sets the Content Security Policy for the specified path (or "*" for a global CSP).
/// If a specific CSP is set, it takes precedence over the global CSP.
/// If no specific or global CSP is set, a default CSP is used.
#[action]
fn setCsp(path: String, csp: String) {
unimplemented!()
}
/// Deletes the Content Security Policy for the specified path (or "*" for the global CSP).
#[action]
fn deleteCsp(path: String) {
unimplemented!()
}
/// Enables/disables caching of responses (Enabled by default)
/// Cache strategy:
/// - `If-None-Match` header is checked against the hash of the content
/// - The hash is stored in the `ETag` header
/// - If the hash matches, a 304 Not Modified response is returned
/// - If the hash does not match, the new content is returned with an updated `ETag` header
#[action]
fn enableCache(enable: bool) {
unimplemented!()
}
/// If content requested for the sender service is not found, proxy the request to the
/// specified proxy.
#[action]
fn setProxy(proxy: AccountNumber) {
unimplemented!()
}
/// Removes the proxy set with `setProxy`.
#[action]
fn clearProxy() {
unimplemented!()
}
}
#[test]
fn verify_schema() {
crate::assert_schema_matches_package::<Wrapper>();
}