Skip to main content

data_for_seo/entity/on_page/
resources.rs

1use crate::entity::OnPageDataApiCrawlStatus;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5/// Result object for the OnPage Resources endpoint.
6/// See <https://docs.dataforseo.com/v3/on_page/resources/>.
7#[derive(Debug, Default, Serialize, Deserialize, Clone)]
8pub struct OnPageDataApiResources {
9    /// Crawling progress: "in_progress" or "finished".
10    pub crawl_progress: Option<String>,
11    /// Statistics on the crawling session.
12    pub crawl_status: Option<OnPageDataApiCrawlStatus>,
13    /// Total number of matching items in the database.
14    pub total_items_count: Option<i64>,
15    /// Number of items returned in this response.
16    pub items_count: Option<i64>,
17    /// Resources found during the crawl.
18    pub items: Option<Vec<OnPageDataApiResourceItem>>,
19}
20
21/// A single resource discovered during the crawl.
22#[derive(Debug, Default, Serialize, Deserialize, Clone)]
23pub struct OnPageDataApiResourceItem {
24    /// Type of the resource, e.g. "html", "script", "stylesheet", "image".
25    pub resource_type: Option<String>,
26    /// Meta information about the resource.
27    pub meta: Option<OnPageResourceItemMeta>,
28    /// HTTP status code returned for the resource.
29    pub status_code: Option<i32>,
30    /// Redirect target URL, if the resource redirects.
31    pub location: Option<String>,
32    /// Absolute URL of the resource.
33    pub url: Option<String>,
34    /// Uncompressed size of the resource, in bytes.
35    pub size: Option<i64>,
36    /// Encoded (compressed) size of the resource, in bytes.
37    pub encoded_size: Option<i64>,
38    /// Total bytes transferred over the network, including headers.
39    pub total_transfer_size: Option<i64>,
40    /// Timestamp when the resource was fetched (UTC).
41    pub fetch_time: Option<String>,
42    /// Breakdown of the fetch timing for the resource.
43    pub fetch_timing: Option<OnPageResourceItemFetchTiming>,
44    /// Cache-control settings for the resource.
45    pub cache_control: Option<OnPageResourceItemCacheControl>,
46    /// Boolean flags for on-page checks performed on the resource.
47    pub checks: Option<Value>,
48    /// Content encoding applied to the resource, e.g. "gzip".
49    pub content_encoding: Option<String>,
50    /// Media (MIME) type of the resource.
51    pub media_type: Option<String>,
52    /// Category of the resource by accept type, e.g. "text_html".
53    pub accept_type: Option<String>,
54    /// Value of the `Server` response header.
55    pub server: Option<String>,
56    /// Last-modified dates reported for the resource.
57    pub last_modified: Option<OnPageResourceItemLastModified>,
58    /// Errors and warnings found while parsing the resource.
59    pub resource_errors: Option<OnPageResourceItemErrors>,
60}
61
62/// Meta information about a resource, such as image attributes.
63#[derive(Debug, Default, Serialize, Deserialize, Clone)]
64pub struct OnPageResourceItemMeta {
65    /// Alt text of the image resource.
66    pub alternative_text: Option<String>,
67    /// Title attribute of the resource.
68    pub title: Option<String>,
69    /// Original width of the image, in pixels.
70    pub original_width: Option<i32>,
71    /// Original height of the image, in pixels.
72    pub original_height: Option<i32>,
73    /// Rendered width of the image, in pixels.
74    pub width: Option<i32>,
75    /// Rendered height of the image, in pixels.
76    pub height: Option<i32>,
77}
78
79/// Timing breakdown for fetching a resource.
80#[derive(Debug, Default, Serialize, Deserialize, Clone)]
81pub struct OnPageResourceItemFetchTiming {
82    /// Total time to fetch the resource, in milliseconds.
83    pub duration_time: Option<i64>,
84    /// Offset from crawl start when fetching began, in milliseconds.
85    pub fetch_start: Option<i64>,
86    /// Offset from crawl start when fetching ended, in milliseconds.
87    pub fetch_end: Option<i64>,
88}
89
90/// Cache-control settings reported for a resource.
91#[derive(Debug, Default, Serialize, Deserialize, Clone)]
92pub struct OnPageResourceItemCacheControl {
93    /// Whether the resource can be cached.
94    pub cachable: Option<bool>,
95    /// Time the resource stays valid in cache, in seconds.
96    pub ttl: Option<i64>,
97}
98
99/// Last-modified dates reported for a resource from various sources.
100#[derive(Debug, Default, Serialize, Deserialize, Clone)]
101pub struct OnPageResourceItemLastModified {
102    /// Last-modified date from the HTTP response header (UTC).
103    pub header: Option<String>,
104    /// Last-modified date declared in the sitemap (UTC).
105    pub sitemap: Option<String>,
106    /// Last-modified date declared in a meta tag (UTC).
107    pub meta_tag: Option<String>,
108}
109
110/// Errors and warnings collected while parsing a resource.
111#[derive(Debug, Default, Serialize, Deserialize, Clone)]
112pub struct OnPageResourceItemErrors {
113    /// Errors encountered while parsing the resource.
114    pub errors: Option<Vec<OnPageResourceItemError>>,
115    /// Warnings encountered while parsing the resource.
116    pub warnings: Option<Vec<OnPageResourceItemWarning>>,
117}
118
119/// A single parsing error found in a resource.
120#[derive(Debug, Default, Serialize, Deserialize, Clone)]
121pub struct OnPageResourceItemError {
122    /// Line number where the error occurred.
123    pub line: Option<i32>,
124    /// Column number where the error occurred.
125    pub column: Option<i32>,
126    /// Human-readable description of the error.
127    pub message: Option<String>,
128    /// Status code associated with the error.
129    pub status_code: Option<i32>,
130}
131
132/// A single parsing warning found in a resource.
133#[derive(Debug, Default, Serialize, Deserialize, Clone)]
134pub struct OnPageResourceItemWarning {
135    /// Line number where the warning occurred.
136    pub line: Option<i32>,
137    /// Column number where the warning occurred.
138    pub column: Option<i32>,
139    /// Human-readable description of the warning.
140    pub message: Option<String>,
141    /// Status code associated with the warning.
142    pub status_code: Option<i32>,
143}