Skip to content

Commit fc9fdaf

Browse files
committed
Support API version 22
1 parent 741a869 commit fc9fdaf

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

crates/figma-agent/src/payload.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,37 @@ use std::collections::HashMap;
33
use serde::Serialize;
44

55
#[derive(Serialize, Clone)]
6-
#[serde(rename_all = "camelCase")]
76
pub struct FontFilesResult {
87
pub version: i32,
8+
pub package: String,
9+
#[serde(rename = "fontFiles")]
910
pub font_files: HashMap<String, Vec<FontFile>>,
1011
}
1112

1213
#[derive(Serialize, Clone)]
13-
#[serde(rename_all = "camelCase")]
1414
pub struct FontFile {
1515
#[serde(skip_serializing)]
1616
pub path: String,
1717
#[serde(skip_serializing)]
1818
pub index: i32,
1919

20+
pub user_installed: bool,
21+
pub modified_at: u64,
22+
2023
pub postscript: String,
2124
pub family: String,
2225
pub style: String,
2326
pub weight: i32,
2427
pub italic: bool,
25-
pub width: i32,
28+
pub stretch: i32,
2629

2730
#[serde(skip_serializing)]
2831
pub is_variable: bool,
29-
#[serde(skip_serializing_if = "Option::is_none")]
32+
#[serde(rename = "variationAxes", skip_serializing_if = "Option::is_none")]
3033
pub variation_axes: Option<Vec<VariationAxis>>,
3134
}
3235

3336
#[derive(Serialize, Clone)]
34-
#[serde(rename_all = "camelCase")]
3537
pub struct VariationAxis {
3638
pub name: String,
3739
pub tag: String,

crates/figma-agent/src/routes/font_files.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::{collections::HashMap, fs, time::UNIX_EPOCH};
22

33
use actix_web::{get, web, Responder};
44
use figma_agent::{PatternHelpers, CONFIG, FC, FONT_CACHE};
@@ -40,7 +40,8 @@ pub async fn font_files() -> impl Responder {
4040
font_cache.borrow_mut().write();
4141

4242
web::Json(payload::FontFilesResult {
43-
version: 20,
43+
version: 22,
44+
package: "116.10.8".to_owned(), // latest version as of 2023-06-22
4445
font_files,
4546
})
4647
}
@@ -53,6 +54,14 @@ fn get_font_file(pattern: &Pattern) -> Option<payload::FontFile> {
5354
path: path.to_owned(),
5455
index,
5556

57+
user_installed: true,
58+
modified_at: fs::metadata(path)
59+
.and_then(|metadata| metadata.modified())
60+
.ok()
61+
.and_then(|modified_time| modified_time.duration_since(UNIX_EPOCH).ok())
62+
.map(|duration| duration.as_secs())
63+
.unwrap_or(0),
64+
5665
postscript: pattern.postscript_name().unwrap_or("").to_owned(),
5766
family: pattern.family().unwrap_or("").to_owned(),
5867
style: pattern.style().unwrap_or("").to_owned(),
@@ -61,7 +70,7 @@ fn get_font_file(pattern: &Pattern) -> Option<payload::FontFile> {
6170
.slant()
6271
.map(|slant| slant != FC_SLANT_ROMAN)
6372
.unwrap_or(false),
64-
width: pattern.os_width_class().unwrap_or(5),
73+
stretch: pattern.os_width_class().unwrap_or(5),
6574

6675
is_variable: pattern.is_variable().unwrap_or(false),
6776
variation_axes: None,

0 commit comments

Comments
 (0)