Edits history of script submission #3715 for ' Get avatar image by type (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get avatar image by type
     * Returns the default project or issue type avatar image.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** None.
     */
    export async function main(
      auth: Jira,
      type: "issuetype" | "project",
      size: "xsmall" | "small" | "medium" | "large" | "xlarge" | undefined,
      format: "png" | "svg" | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/universal_avatar/view/type/${type}`
      );
      for (const [k, v] of [
        ["size", size],
        ["format", format],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get avatar image by type
     * Returns the default project or issue type avatar image.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** None.
     */
    export async function main(
      auth: Jira,
      type: "issuetype" | "project",
      size: "xsmall" | "small" | "medium" | "large" | "xlarge" | undefined,
      format: "png" | "svg" | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/universal_avatar/view/type/${type}`
      );
      for (const [k, v] of [
        ["size", size],
        ["format", format],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 948 days ago