Migrate imgb64 to jimp (#163)
This commit is contained in:
@@ -7,13 +7,13 @@
|
||||
import processes from "child_process"
|
||||
import axios from "axios"
|
||||
import puppeteer from "puppeteer"
|
||||
import imgb64 from "image-to-base64"
|
||||
import git from "simple-git"
|
||||
import twemojis from "twemoji-parser"
|
||||
import jimp from "jimp"
|
||||
import opengraph from "open-graph-scraper"
|
||||
|
||||
//Exports
|
||||
export {fs, os, paths, url, util, processes, axios, puppeteer, imgb64, git}
|
||||
export {fs, os, paths, url, util, processes, axios, puppeteer, git, opengraph}
|
||||
|
||||
/**Returns module __dirname */
|
||||
export function __module(module) {
|
||||
@@ -128,6 +128,19 @@
|
||||
return false
|
||||
}
|
||||
|
||||
/**Image to base64 */
|
||||
export async function imgb64(image, {width, height, fallback = true} = {}) {
|
||||
//Undefined image
|
||||
if (!image)
|
||||
return fallback ? "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==" : null
|
||||
//Load image
|
||||
image = await jimp.read(image)
|
||||
//Resize image
|
||||
if ((width)&&(height))
|
||||
image = image.resize(width, height)
|
||||
return image.getBase64Async(jimp.AUTO)
|
||||
}
|
||||
|
||||
/**SVG utils */
|
||||
export const svg = {
|
||||
/**Render and resize svg */
|
||||
@@ -196,7 +209,7 @@
|
||||
try {
|
||||
for (const [emoji, url] of Object.entries((await rest.emojis.get()).data).map(([key, value]) => [`:${key}:`, value])) {
|
||||
if (((!emojis.has(emoji)))&&(new RegExp(emoji, "g").test(rendered)))
|
||||
emojis.set(emoji, `<img class="gemoji" src="data:image/png;base64,${await imgb64(url)}" height="16" width="16" alt="">`)
|
||||
emojis.set(emoji, `<img class="gemoji" src="${await imgb64(url)}" height="16" width="16" alt="">`)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
title:"Final Screenshot",
|
||||
score:null,
|
||||
details:{
|
||||
data:"data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
data:null,
|
||||
type:"screenshot",
|
||||
timestamp:Date.now(),
|
||||
},
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
next = cursor.hasNextPage
|
||||
for (const {name:{full:name}, image:{medium:artwork}} of nodes) {
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > processing ${name}`)
|
||||
characters.push({name, artwork:artwork ? await imports.imgb64(artwork) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="})
|
||||
characters.push({name, artwork:await imports.imgb64(artwork)})
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -142,7 +142,7 @@
|
||||
description:description.replace(/<br\s*\\?>/g, " "),
|
||||
scores:{user:userScore, community:averageScore},
|
||||
released:type === "ANIME" ? episodes : chapters,
|
||||
artwork:artwork ? await imports.imgb64(artwork) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
artwork:await imports.imgb64(artwork),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
continue
|
||||
}
|
||||
if (!(login in contributors))
|
||||
contributors[login] = {avatar:avatar ? await imports.imgb64(avatar) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==", contributions:1, pr:[]}
|
||||
contributors[login] = {avatar:await imports.imgb64(avatar), contributions:1, pr:[]}
|
||||
else {
|
||||
contributors[login].contributions++
|
||||
contributors[login].pr.push(...(message.match(/(?<=[(])#\d+(?=[)])/g) ?? []))
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
}
|
||||
//Convert avatars to base64
|
||||
console.debug(`metrics/compute/${login}/plugins > people > loading avatars`)
|
||||
await Promise.all(result[type].map(async user => user.avatar = user.avatarUrl ? await imports.imgb64(user.avatarUrl) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="))
|
||||
await Promise.all(result[type].map(async user => user.avatar = await imports.imgb64(user.avatarUrl)))
|
||||
}
|
||||
|
||||
//Results
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
</h2>
|
||||
<% for (const {name, type, description, release, status, genres, scores, progress, released, artwork} of plugins.anilist.lists[media][list]) { %>
|
||||
<div class="media">
|
||||
<img src="data:image/png;base64,<%= artwork %>" width="48" height="72" alt=""/>
|
||||
<img src="<%= artwork %>" width="48" height="72" alt=""/>
|
||||
<div class="about">
|
||||
<div class="name">
|
||||
<%= name %>
|
||||
@@ -116,7 +116,7 @@
|
||||
</h2>
|
||||
<div class="characters">
|
||||
<% for (const {name, artwork} of plugins.anilist.characters) { %>
|
||||
<img src="data:image/png;base64,<%= artwork %>" width="36" height="54" alt=""/>
|
||||
<img src="<%= artwork %>" width="36" height="54" alt=""/>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<% if (account === "user") { %>
|
||||
<section>
|
||||
<h1 class="field">
|
||||
<img class="avatar" src="data:image/png;base64,<%= computed.avatar %>" width="20" height="20" />
|
||||
<img class="avatar" src="<%= computed.avatar %>" width="20" height="20" />
|
||||
<span><%= user.name || user.login %></span>
|
||||
</h1>
|
||||
<div class="row">
|
||||
@@ -47,7 +47,7 @@
|
||||
<% } else if (account === "organization") { %>
|
||||
<section>
|
||||
<h1 class="field">
|
||||
<img class="avatar organization" src="data:image/png;base64,<%= computed.avatar %>" width="20" height="20" />
|
||||
<img class="avatar organization" src="<%= computed.avatar %>" width="20" height="20" />
|
||||
<span><%= user.name || user.login %></span>
|
||||
</h1>
|
||||
<div class="row">
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="tracklist">
|
||||
<% for (const {name = "", artist = "", artwork = "", played_at = ""} of plugins.music.tracks) { %>
|
||||
<div class="track">
|
||||
<img src="data:image/png;base64,<%= artwork %>" width="<%= plugins.music.played_at ? 48 : 32 %>" height="<%= plugins.music.played_at ? 48 : 32 %>" alt=""/>
|
||||
<img src="<%= artwork %>" width="<%= plugins.music.played_at ? 48 : 32 %>" height="<%= plugins.music.played_at ? 48 : 32 %>" alt=""/>
|
||||
<div class="infos">
|
||||
<div class="name"><%= name %></div>
|
||||
<div class="artist"><%= artist %></div>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<%= plugins.people.error.message %>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<% for (const user of plugins.people[type]) { %><img class="avatar" src="data:image/png;base64,<%= user.avatar %>" width="<%= plugins.people.size %>" height="<%= plugins.people.size %>" alt="" /><% } %>
|
||||
<% for (const user of plugins.people[type]) { %><img class="avatar" src="<%= user.avatar %>" width="<%= plugins.people.size %>" height="<%= plugins.people.size %>" alt="" /><% } %>
|
||||
<% } %>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<% } else if (plugins.topics.mode === "mastered") { %>
|
||||
<% for (const {name, icon} of plugins.topics.list) { %>
|
||||
<% if (icon) { %>
|
||||
<img src="data:image/png;base64,<%= icon %>" width="24" height="24" alt="<%= name %>" title="<%= name %>"/>
|
||||
<img src="<%= icon %>" width="24" height="24" alt="<%= name %>" title="<%= name %>"/>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<% } else { %>
|
||||
<% for (const [login, {avatar, contributions}] of Object.entries(plugins.contributors.list)) { %>
|
||||
<div class="label">
|
||||
<img class="avatar" src="data:image/png;base64,<%= avatar %>" width="22" height="22" alt="" />
|
||||
<img class="avatar" src="<%= avatar %>" width="22" height="22" alt="" />
|
||||
<%= login %>
|
||||
<% if (plugins.contributors.contributions) { %>
|
||||
<div class="contributions"><%= contributions %> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M10.5 7.75a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm1.43.75a4.002 4.002 0 01-7.86 0H.75a.75.75 0 110-1.5h3.32a4.001 4.001 0 017.86 0h3.32a.75.75 0 110 1.5h-3.32z"></path></svg></div>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<%= plugins.people.error.message %>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<% for (const user of plugins.people[type]) { %><img class="avatar" src="data:image/png;base64,<%= user.avatar %>" width="<%= plugins.people.size %>" height="<%= plugins.people.size %>" alt="" /><% } %>
|
||||
<% for (const user of plugins.people[type]) { %><img class="avatar" src="<%= user.avatar %>" width="<%= plugins.people.size %>" height="<%= plugins.people.size %>" alt="" /><% } %>
|
||||
<% } %>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user