import mongoose from 'mongoose' import { uuidToNoSymboUUID } from '../generator.js' import { ImageSecurity } from '../secure.js' import { s3Instance } from '../index.js' import { getSignedUrl } from '@aws-sdk/s3-request-presigner' import { GetObjectCommand } from '@aws-sdk/client-s3' import { config } from '../config.js' export const Player = mongoose.model("Player", new mongoose.Schema({ username: String, // 有符号 UUID password: String, email: String, uuid: String, textures: { skin: String, cape: String, }, registerDate: Number, permissions: [{ type: String }], binding: { username: String, platform: String, verified: Boolean, } })) export const PlayerSeriliazationSchema = { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "properties": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "value": { "type": "string" }, "signature": { "type": "string" } } } } } } export const PlayerAccountSerializationSchema = { "type": "object", "properties": { "id": { "type": "string" }, "properties": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "value": { "type": "string" } } } } } } export async function getPlayerSerialization(player) { const textures = { timestamp: 0, profileId: uuidToNoSymboUUID(player.uuid), profileName: player.username, textures: { } } if(player.textures.skin && player.textures.skin != 0) { // Must be '!=' if this change to '!==' will never works textures.textures.SKIN = { url: await getSignedUrl(s3Instance, new GetObjectCommand({ Bucket: config.storage.bucket, Key: player.textures.skin }), { expiresIn: 3 * 24 * 60 * 60 }) // 3 days } } if(player.textures.cape && player.textures.cape != 0) { // Must be '!=' if this change to '!==' will never works textures.textures.CAPE = { url: await getSignedUrl(s3Instance, new GetObjectCommand({ Bucket: config.storage.bucket, Key: player.textures.cape }), { expiresIn: 3 * 24 * 60 * 60 }) // 3 days } } const val = Buffer.from(JSON.stringify(textures)).toString('base64') return { id: uuidToNoSymboUUID(player.uuid), name: player.username, properties: [ { name: "texturs", value: val, signature: ImageSecurity.sign(val), } ] } }