mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-05 02:35:08 +02:00
Jpeg conversion because OPENSEA LIED
This commit is contained in:
parent
49e725f2cf
commit
4eec540d71
BIN
functions/assets/temp.jpg
Normal file
BIN
functions/assets/temp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 339 KiB |
BIN
functions/assets/temp.png
Normal file
BIN
functions/assets/temp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
1014
functions/firebase-debug.log
Normal file
1014
functions/firebase-debug.log
Normal file
File diff suppressed because it is too large
Load Diff
@ -79,13 +79,20 @@ async function generateRocketeer( id, network='mainnet' ) {
|
||||
value: `rgb( ${ randomNumberBetween( 0, 255 ) }, ${ randomNumberBetween( 0, 255 ) }, ${ randomNumberBetween( 0, 255 ) } )`
|
||||
} )
|
||||
|
||||
// Set birthday
|
||||
rocketeer.attributes.push( {
|
||||
"display_type": "date",
|
||||
"trait_type": "birthday",
|
||||
"value": Date.now() / 1000
|
||||
} )
|
||||
|
||||
// Special editions
|
||||
const edition = { "trait_type": "edition", value: "regular" }
|
||||
if( id > 50 ) edition.value = 'genesis'
|
||||
if( id % 42 === 0 ) edition.value = 'hitchhiker'
|
||||
|
||||
// Generate, compile and upload image
|
||||
rocketeer.image = await svgFromAttributes( rocketeer.attributes, `${ network }Rocketeers/${id}.svg` )
|
||||
rocketeer.image = await svgFromAttributes( rocketeer.attributes, `${ network }Rocketeers/${id}` )
|
||||
|
||||
// Save new Rocketeer
|
||||
await db.collection( `${ network }Rocketeers` ).doc( id ).set( rocketeer )
|
||||
@ -96,13 +103,13 @@ async function generateRocketeer( id, network='mainnet' ) {
|
||||
|
||||
async function safelyReturnRocketeer( id, network ) {
|
||||
|
||||
// Chech if this is an illegal ID
|
||||
const invalidId = await isInvalidRocketeerId( id, network )
|
||||
if( invalidId ) throw invalidId
|
||||
// // Chech if this is an illegal ID
|
||||
// const invalidId = await isInvalidRocketeerId( id, network )
|
||||
// if( invalidId ) throw invalidId
|
||||
|
||||
// Get old rocketeer if it exists
|
||||
const oldRocketeer = await getExistingRocketeer( id, network )
|
||||
if( oldRocketeer ) return oldRocketeer
|
||||
// // Get old rocketeer if it exists
|
||||
// const oldRocketeer = await getExistingRocketeer( id, network )
|
||||
// if( oldRocketeer ) return oldRocketeer
|
||||
|
||||
// If no old rocketeer exists, make a new one and save it
|
||||
return generateRocketeer( id, network )
|
||||
|
@ -2,9 +2,10 @@ const masterPath = `${ __dirname }/../assets/master.svg`
|
||||
const jsdom = require("jsdom")
|
||||
const { JSDOM } = jsdom
|
||||
const { promises: fs } = require( 'fs' )
|
||||
|
||||
const { getStorage } = require( 'firebase-admin/storage' )
|
||||
|
||||
// SVG to JPEG
|
||||
const { convert } = require("convert-svg-to-jpeg")
|
||||
|
||||
module.exports = async function svgFromAttributes( attributes=[], path='' ) {
|
||||
|
||||
@ -113,23 +114,34 @@ module.exports = async function svgFromAttributes( attributes=[], path='' ) {
|
||||
replace( defaultVisor, visor_color )
|
||||
replace( defaultBackpack, backpack_color )
|
||||
|
||||
const bakedSvg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">${ document.querySelector( 'svg' ).outerHTML }`
|
||||
const bakedSvg = [
|
||||
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>`,
|
||||
`<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">`,
|
||||
document.querySelector( 'svg' ).outerHTML
|
||||
].join( '' )
|
||||
|
||||
const bakedRaster = await convert( bakedSvg, { } )
|
||||
|
||||
await fs.writeFile( `${ __dirname }/../assets/temp.jpg`, bakedRaster )
|
||||
|
||||
// Store file on firebase
|
||||
const storage = getStorage()
|
||||
const bucket = storage.bucket()
|
||||
|
||||
// Make file reference
|
||||
const file = bucket.file( path )
|
||||
const svgFile = bucket.file( `${path}.svg` )
|
||||
const resterFile = bucket.file( `${path}.jpg` )
|
||||
|
||||
// Save file buffer
|
||||
await file.save( bakedSvg )
|
||||
// Save files
|
||||
await svgFile.save( bakedSvg )
|
||||
await resterFile.save( bakedRaster )
|
||||
|
||||
// Make file public
|
||||
await file.makePublic( )
|
||||
await svgFile.makePublic( )
|
||||
await resterFile.makePublic( )
|
||||
|
||||
// Return public url
|
||||
return file.publicUrl()
|
||||
return resterFile.publicUrl()
|
||||
|
||||
|
||||
}
|
824
functions/package-lock.json
generated
824
functions/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"convert-svg-to-jpeg": "^0.5.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"firebase-admin": "^10.0.0",
|
||||
|
@ -22,7 +22,10 @@ require('dotenv').config()
|
||||
|
||||
// const HDWalletProvider = require('@truffle/hdwallet-provider');
|
||||
const LedgerWalletProvider = require('truffle-ledger-provider');
|
||||
const ledgerOptions = {}
|
||||
const ledgerOptions = {
|
||||
index: process.env.LEDGER_INDEX,
|
||||
path: process.env.LEDGER_PATH
|
||||
}
|
||||
|
||||
// Copied from https://github.com/ProjectOpenSea/opensea-creatures
|
||||
const MNEMONIC = process.env.MNEMONIC;
|
||||
|
Loading…
x
Reference in New Issue
Block a user