Edits history of script submission #4918 for ' Change Browser Cache TTL setting (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Change Browser Cache TTL setting
     * Browser Cache TTL (in seconds) specifies how long Cloudflare-cached resources will remain on your visitors' computers. Cloudflare will honor any larger times specified by your server. (https://support.cloudflare.com/hc/en-us/articles/200168276).
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      body: {
        value:
          | 0
          | 30
          | 60
          | 120
          | 300
          | 1200
          | 1800
          | 3600
          | 7200
          | 10800
          | 14400
          | 18000
          | 28800
          | 43200
          | 57600
          | 72000
          | 86400
          | 172800
          | 259200
          | 345600
          | 432000
          | 691200
          | 1382400
          | 2073600
          | 2678400
          | 5356800
          | 16070400
          | 31536000;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/browser_cache_ttl`
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Change Browser Cache TTL setting
     * Browser Cache TTL (in seconds) specifies how long Cloudflare-cached resources will remain on your visitors' computers. Cloudflare will honor any larger times specified by your server. (https://support.cloudflare.com/hc/en-us/articles/200168276).
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      body: {
        value:
          | 0
          | 30
          | 60
          | 120
          | 300
          | 1200
          | 1800
          | 3600
          | 7200
          | 10800
          | 14400
          | 18000
          | 28800
          | 43200
          | 57600
          | 72000
          | 86400
          | 172800
          | 259200
          | 345600
          | 432000
          | 691200
          | 1382400
          | 2073600
          | 2678400
          | 5356800
          | 16070400
          | 31536000;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/browser_cache_ttl`
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago