Skip to main content

junobuild_cdn/proposals/workflows/
pre_commit_assets.rs

1use crate::proposals::{Proposal, ProposalType};
2use crate::strategies::CdnCommitAssetsStrategy;
3use junobuild_collections::constants::assets::COLLECTION_ASSET_KEY;
4
5pub fn pre_commit_assets(
6    cdn_commit_assets: &impl CdnCommitAssetsStrategy,
7    proposal: &Proposal,
8) -> Result<(), String> {
9    match &proposal.proposal_type {
10        ProposalType::AssetsUpgrade(ref options) => {
11            // Clear existing assets if required.
12            if let Some(true) = options.clear_existing_assets {
13                cdn_commit_assets.delete_assets(&COLLECTION_ASSET_KEY.to_string())?;
14            }
15        }
16        ProposalType::SegmentsDeployment(_) => (),
17    }
18
19    Ok(())
20}