Edits history of script submission #15330 for ' Reset look and feel settings (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Reset look and feel settings
     * Resets the custom look and feel settings for the site or a single space.
    This changes the values of the custom settings to be the same as the
    default settings. It does not change which settings (default or custom)
    are selected. Note, the default space settings are inherited from the
    current global settings.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    'Admin' permission for the space.
     */
    export async function main(auth: Confluence, spaceKey: string | undefined) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/settings/lookandfeel/custom`)
    	for (const [k, v] of [['spaceKey', spaceKey]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 235 days ago