tinymist_package/pack/
release.rs

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
use ecow::EcoString;

use super::*;

/// A package in the GitHub releases.
#[derive(Debug, Clone)]
pub struct GitHubReleasePack {
    /// The package specifier.
    pub specifier: PackageSpec,
    /// The URL of the package.
    pub repo: EcoString,
    /// The name of the package.
    pub name: EcoString,
}

impl PackFs for GitHubReleasePack {
    fn read_all(
        &mut self,
        f: &mut (dyn FnMut(&str, PackFile) -> PackageResult<()> + Send + Sync),
    ) -> PackageResult<()> {
        let url = format!(
            "https://api.github.com/repos/{}/releases/latest/{}",
            self.repo, self.name,
        );

        HttpPack::new(self.specifier.clone(), url).read_all(f)
    }
}

impl Pack for GitHubReleasePack {}
impl PackExt for GitHubReleasePack {}