Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] TV show support #18

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

.env

# dependencies
/node_modules
/.pnp
Expand Down
File renamed without changes.
83 changes: 83 additions & 0 deletions api/content/[contents]/[content].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// import stream from 'stream';
// import url from 'url';
// import {Readable} from 'node:stream';
// const fetch = require("node-fetch");

import uuidByString from "uuid-by-string";
// import Head from "next/head";

// import styles from "../../styles/ContentObject.module.css";
import { Ctx, saveContent } from "../../clients/context.js";
import {
cleanName,
formatImages,
formatUrls,
getGalleryArray,
getSections,
} from "../../utils.js";
import { generateItem } from "../../datasets/dataset-generator.js";
import { formatItemText } from "../../datasets/dataset-parser.js";
import { getDatasetSpecs } from "../../datasets/dataset-specs.js";
// import React, { useState } from "react";
// import { UserBox } from "../../src/components/user-box/UserBox";
// import { EditSource } from "../../src/components/edit-source";
// import {
// LeftSection,
// RightSection,
// } from "../../src/components/content-sections";
// import { MiniMap } from "../../src/components/mini-map/MiniMap";
// import { ImageLoader } from "../../src/components/image-loader/ImageLoader";
// import { MetaTags } from "../../src/components/meta-tags/MetaTags";

const proxy = async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');

const match = req.url.match(/^\/api\/content\/([^\/]*)\/([^\/]*)/);
let type = match ? match[1].replace(/s$/, "") : "";
let name = match ? match[2] : "";
name = decodeURIComponent(name);
name = cleanName(name);

const c = new Ctx();
const title = `${type}/${name}`;
const id = uuidByString(title);
const query = await c.databaseClient.getByName("Content", title);
if (query) {
const { content } = query;
return {
type,
id,
title,
content,
};
} else {
const c = new Ctx();
const [datasetSpecs, generatedItem] = await Promise.all([
getDatasetSpecs(),
generateItem(type, name),
]);
const datasetSpec = datasetSpecs.find((ds) => ds.type === type);
// console.log('got datset spec', {datasetSpec});
const itemText = formatItemText(generatedItem, datasetSpec);

// const imgUrl = `/api/characters/${name}/images/main.png`;

const content = `\
${itemText}
`;
// ![](${encodeURI(imgUrl)})

await c.databaseClient.setByName("Content", title, content);

return {
type,
id,
title,
content,
};
}
};
export default proxy;
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import stream from "stream";
import { Ctx } from "../../../../clients/context.js";
import { getDatasetSpecs } from "../../../../datasets/dataset-specs.js";
import { cleanName } from "../../../../utils.js";
import { generateImage } from "../../../../media/images/image-generator.js";
import { Ctx } from "../../../clients/context.js";
import { cleanName } from "../../../utils.js";
import { generateImage } from "../../../media/images/image-generator.js";

//

const globalImagePrompt = `trending on ArtStation`;

//

const CharacterImage = async (req, res) => {
const props = await CharacterImage.getInitialProps({ req });
export default async (req, res) => {
const props = await getInitialProps({ req });
if (props) {
const { imgUrl } = props;

Expand All @@ -29,33 +28,37 @@ const CharacterImage = async (req, res) => {
}
};

CharacterImage.getInitialProps = async (ctx) => {
const getInitialProps = async (ctx) => {
const { req } = ctx;

// Check if ?reroll=true is passed in the query
const isReRoll = req.query?.reroll;
const isReRoll = !!req.query?.reroll;
const modelName = req.query?.model ?? null;

console.log(req.url);
// Clean url from passed values after ?
const reqUrlClean = req.url.replace(/\?.*$/, "");

const match = reqUrlClean.match(/^\/api\/images\/([^\/]*)\/([^\/]*)\.png$/);
// console.log('image match', match);

const c = new Ctx(process.env);

// Moved the generate image to a reusable function
// so it can be called to re-generate the image as well
const generateNewImage = async (
datasetSpec,
// datasetSpec,
description,
imageName,
imageTitle
) => {
const c = new Ctx();
const { imagePrompt } = datasetSpec;
const c = new Ctx(process.env);
// const { imagePrompt } = datasetSpec;

const generateCharacterImage = generateImage({
modelName: null,
modelName,
// suffix: 'anime style video game character concept, full body',
suffix: `${imagePrompt}, ${globalImagePrompt}`,
// suffix: `${imagePrompt}, ${globalImagePrompt}`,
// suffix: imagePrompt,
// seed: [512, 512, 64, 128, 1, 256],
});
let imgArrayBuffer = await generateCharacterImage(description); // XXX make this based on the type
Expand All @@ -66,7 +69,10 @@ CharacterImage.getInitialProps = async (ctx) => {
file.name = imageName;
const hash = await c.storageClient.uploadFile(file);

await c.databaseClient.setByName("IpfsData", imageTitle, hash);
// console.log('image query set', imageTitle, hash);
await c.databaseClient.setByName("IpfsData", imageTitle, {
hash,
});

const imgUrl = c.storageClient.getUrl(hash, file.name);

Expand All @@ -83,48 +89,40 @@ CharacterImage.getInitialProps = async (ctx) => {
let description = match[2];
description = decodeURIComponent(description);
description = cleanName(description);

const imageTitle = `images/${type}/${description}`;
const imageName = `${description}.png`;

const datasetSpecs = await getDatasetSpecs();
const datasetSpec = datasetSpecs.find(
(spec) => spec.type === singleType
const imageQuery = await c.databaseClient.getByName(
"IpfsData",
imageTitle
);
if (datasetSpec) {
const imageTitle = `images/${type}/${description}`;
const imageName = `${description}.png`;

const c = new Ctx();
const imageQuery = await c.databaseClient.getByName(
"IpfsData",
imageTitle
);
if (imageQuery) {
if (isReRoll) {
return await generateNewImage(
datasetSpec,
description,
imageName,
imageTitle
);
} else {
const { content: ipfsHash } = imageQuery;
const imgUrl = c.storageClient.getUrl(ipfsHash, imageName);
return {
imgUrl,
};
}
} else {
console.log('image query 1', imageQuery, imageTitle)
if (imageQuery) {
if (isReRoll) {
return await generateNewImage(
datasetSpec,
// datasetSpec,
description,
imageName,
imageTitle
);
} else {
// const { content: ipfsHashSpec } = imageQuery;
const { hash: ipfsHash } = imageQuery;
const imgUrl = c.storageClient.getUrl(ipfsHash, imageName);
return {
imgUrl,
};
}
} else {
return null;
return await generateNewImage(
// datasetSpec,
description,
imageName,
imageTitle
);
}
} else {
return null;
}
};
export default CharacterImage;
};
File renamed without changes.
52 changes: 27 additions & 25 deletions certs-local/fullchain.pem
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIE3zCCA8egAwIBAgISA84yViiyzIEfb3B0b2VFeJVVMA0GCSqGSIb3DQEBCwUA
MIIFYjCCBEqgAwIBAgISA5GBcmkZ8ja5Bbb98XM313DvMA0GCSqGSIb3DQEBCwUA
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
EwJSMzAeFw0yMjEyMTcxNzIzNThaFw0yMzAzMTcxNzIzNTdaMB4xHDAaBgNVBAMT
E2xvY2FsLndlYmF2ZXJzZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARi
cEMESIfVm5Swsbz8X6zxRmEOwufbU5FACaNobQiswG0DXNhATp2uc8aKk81KWC8K
Jk+LAGkEwSCbWQfwViWso4ICzDCCAsgwDgYDVR0PAQH/BAQDAgeAMB0GA1UdJQQW
MBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBR5
tSvOyPQID9c9rT8AIzWkQlqepzAfBgNVHSMEGDAWgBQULrMXt1hWy65QCUDmH6+d
EwJSMzAeFw0yMzAzMDIwMDIzMjBaFw0yMzA1MzEwMDIzMTlaMB4xHDAaBgNVBAMT
E2xvY2FsLndlYmF2ZXJzZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASF
4nxIBcHwzfn7twK3TAP4ZZfG79oeH/LlOE6O8i4zde3GFdwhPKTlvjVbR6uDhOAX
CcotZK2BjFtdGVgQit2Uo4IDTzCCA0swDgYDVR0PAQH/BAQDAgeAMB0GA1UdJQQW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BrE3ACPmT0YM
+64+hHmRFe3kPexsx6s8ggIgG6ux/PHEGt8Ov1wafh1BTlDxPjRpDiqttxPJInPy
y/0wDQYJKoZIhvcNAQELBQADggEBADrkDiDZeKmbySucbF9zHiTtx5pVw+49KT52
vwupzNQ5Io0+xArkCGOiDVkNJwA8NIC1X82Tt+VZSB58be3IBaFF2vMjaLfCJtld
mGeTDgySklOD3HcZGruRQzOLy7OzdGvXxPXXn9JulfeL6KtFg7uQ/xSyc4U1Thz7
uAq97ZW997/xllad+dco+Z2IYjDqK9rEkmKGYnPM06gPjOYn4ozditZS6y1O1/ZW
c9L0dZLl3s4S5RJ4RJ/1tIqUZlPcvliHOMeHaWqB/HbTZggNv7ocv4pUmNVO+sKP
iIMLNri9RZOPQNmQ+OZ5d4TU6ypkC49e0nTtYR0T0F/Lu67kFG0=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
Expand Down
6 changes: 3 additions & 3 deletions certs-local/privkey.pem
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgCQF/BrIhiYtr54Is
biZ5qkBWJHKdXCnk6L/qWYxfWAShRANCAARicEMESIfVm5Swsbz8X6zxRmEOwufb
U5FACaNobQiswG0DXNhATp2uc8aKk81KWC8KJk+LAGkEwSCbWQfwViWs
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgJ5Xpig/AkaOunT1l
CyrOl1VTvwBhxhqUdyA5zZsXcmWhRANCAASF4nxIBcHwzfn7twK3TAP4ZZfG79oe
H/LlOE6O8i4zde3GFdwhPKTlvjVbR6uDhOAXCcotZK2BjFtdGVgQit2U
-----END PRIVATE KEY-----
Loading