webp support for api

This commit is contained in:
David Ralph
2020-04-22 15:22:22 +01:00
parent 148c38085a
commit 69b3a983db
2 changed files with 12 additions and 6 deletions

View File

@@ -1,10 +1,15 @@
//* Imports
import React from 'react';
import supportsWebP from 'supports-webp';
export default class Background extends React.Component {
async setBackground() {
try { // First we try and get an image from the API...
let data = await fetch('https://api.muetab.xyz/getImage?category=Outdoors');
let requestURL;
if (await supportsWebP) requestURL = 'https://api.muetab.xyz/getImage?webp=true';
else requestURL = 'https://api.muetab.xyz/getImage?category=Outdoors';
let data = await fetch(requestURL);
data = await data.json();
document.getElementById('root').style.backgroundImage = `url(${data.file})`; // Set the background