-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rewritten API at /api/v2 - Created API Documentation at /api/v2/docs - Old API is now deprecated - Changed some small tailwind classes - Fixed export by url not working for colors - Fixed format dropdown not updating when importing or using cookies - Removed /resources/gradients endpoint since apparently no one was using it cuz it was erroring this whole time
- Loading branch information
Showing
24 changed files
with
301 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
export const onGet: any = async ({ json }: any) => { | ||
throw json(200, { | ||
endpoints: [ | ||
'/api/gradient', | ||
], | ||
}); | ||
import type { RequestHandler } from '@builder.io/qwik-city'; | ||
|
||
export const onGet: RequestHandler = async ({ json }) => { | ||
throw json(200, { | ||
endpoints: { | ||
'/api/v2': { | ||
type: 'GET', | ||
description: 'View the v2 API endpoints.', | ||
}, | ||
'/api/gradient': { | ||
type: 'GET', | ||
description: 'Generate a gradient.', | ||
WARNING: '/api/gradient is deprecated. Please use /api/v2/rgb instead.', | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { component$ } from '@builder.io/qwik'; | ||
import { routeLoader$, type DocumentHead } from '@builder.io/qwik-city'; | ||
import { Card, Header } from '@luminescent/ui'; | ||
|
||
import { DocumentOutline } from 'qwik-ionicons'; | ||
import { defaults, v3formats } from '~/components/util/PresetUtils'; | ||
|
||
export const useEndpoints = routeLoader$(async ({ url }) => { | ||
const data = await fetch(url.origin + '/api/v2'); | ||
const json = await data.json(); | ||
const paths = Object.keys(json.endpoints); | ||
for (const path of paths) { | ||
const endpointData = await fetch(url.origin + path); | ||
const endpointJson = await endpointData.json(); | ||
json.endpoints[path] = { ...json.endpoints[path], options: endpointJson.options }; | ||
} | ||
return json; | ||
}); | ||
|
||
export default component$(() => { | ||
const { endpoints } = useEndpoints().value; | ||
|
||
return <> | ||
<section class="flex flex-col gap-3 mx-auto max-w-7xl px-6 py-16 min-h-svh"> | ||
<div> | ||
<h1 class="flex gap-4 items-center text-gray-100 text-2xl sm:text-4xl font-bold my-12 drop-shadow-lg"> | ||
<DocumentOutline width="64" /> RGBirdflop API Docs | ||
</h1> | ||
<p class="text-red-500 mb-6"> | ||
The /api/gradient endpoint is deprecated and will be removed in the future in favor of this new API. Please update your code to use the new API. | ||
</p> | ||
<h2 class="flex gap-4 items-center text-gray-100 text-xl sm:text-3xl font-bold mb-3 drop-shadow-lg"> | ||
Get Started | ||
</h2> | ||
<p> | ||
This API is used to generate RGB gradient text for Minecraft and is based on JSON. Useful for creating gradient text in your own code for anything Minecraft-related. | ||
The API has default values that are the same as the RGBirdflop website, which are also shown in the docs below. | ||
To generate a gradient, make a GET request to /api/v2/rgb. The API will return a JSON object with the gradient output. | ||
</p> | ||
<h2 class="flex gap-4 items-center text-gray-100 text-xl sm:text-3xl font-bold mt-12 mb-6 drop-shadow-lg"> | ||
Endpoints | ||
</h2> | ||
<div> | ||
{Object.keys(endpoints).map((path) => <div key={path}> | ||
<h3 class="flex gap-4 items-center text-gray-100 text-lg sm:text-2xl font-bold mb-1 drop-shadow-lg"> | ||
{endpoints[path].type} {path} | ||
</h3> | ||
<h4 class="flex gap-4 items-center text-gray-400 sm:text-lg mb-2 drop-shadow-lg"> | ||
{endpoints[path].description} | ||
</h4> | ||
<h4 class="flex gap-4 items-center text-gray-400 sm:text-lg mb-2 drop-shadow-lg"> | ||
Options | ||
</h4> | ||
<Card> | ||
{Object.keys(endpoints[path].options).map(option => { | ||
return <div key={option}> | ||
<p class="font-bold text-white">{option}</p> | ||
<p>type: {endpoints[path].options[option].type}</p> | ||
<p class="text-gray-400">{endpoints[path].options[option].description}</p> | ||
<p class="text-gray-500">default: {JSON.stringify(endpoints[path].options[option].default, null, 1)}</p> | ||
</div>; | ||
})} | ||
</Card> | ||
</div>)} | ||
</div> | ||
<h2 class="flex gap-4 items-center text-gray-100 text-xl sm:text-3xl font-bold mt-12 mb-6 drop-shadow-lg"> | ||
Data Models | ||
</h2> | ||
<Card> | ||
<Header id="formatobject" anchor> | ||
Format Object | ||
</Header> | ||
<div> | ||
<p class="font-bold text-white">color</p> | ||
<p class="text-red-500">required</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The format to use for the color codes. $1 = #(r)rggbb, $2 = #r(r)ggbb, $3 = #rr(g)gbb, $4 = #rrg(g)bb, $5 = #rrgg(b)b, $6 = #rrggb(b), $f = format tags, $c = the character</p> | ||
<p class="text-gray-500">example: "{defaults.format.color}" or "MiniMessage"</p> | ||
</div> | ||
<div> | ||
<p class="font-bold text-white">char</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The character to use for the format tags. (such as &l, &o, &n, &m)</p> | ||
<p class="text-gray-500">example: "{defaults.format.char}"</p> | ||
</div> | ||
<div> | ||
<p class="font-bold text-white">bold</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The code to use for making the text bold. $t is where the output text will go. If $t is not included, the output will not show.</p> | ||
<p class="text-gray-500">example: {v3formats.find(format => format.color == 'MiniMessage')?.bold}</p> | ||
</div> | ||
<div> | ||
<p class="font-bold text-white">italic</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The code to use for making the text italic. $t is where the output text will go. If $t is not included, the output will not show.</p> | ||
<p class="text-gray-500">example: {v3formats.find(format => format.color == 'MiniMessage')?.italic}</p> | ||
</div> | ||
<div> | ||
<p class="font-bold text-white">underline</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The code to use for making the text underline. $t is where the output text will go. If $t is not included, the output will not show.</p> | ||
<p class="text-gray-500">example: {v3formats.find(format => format.color == 'MiniMessage')?.underline}</p> | ||
</div> | ||
<div> | ||
<p class="font-bold text-white">strikethrough</p> | ||
<p>type: string</p> | ||
<p class="text-gray-400">The code to use for making the text strikethrough. $t is where the output text will go. If $t is not included, the output will not show.</p> | ||
<p class="text-gray-500">example: {v3formats.find(format => format.color == 'MiniMessage')?.strikethrough}</p> | ||
</div> | ||
</Card> | ||
</div> | ||
</section> | ||
</>; | ||
}); | ||
|
||
export const head: DocumentHead = { | ||
title: 'RGBirdflop API Docs', | ||
meta: [ | ||
{ | ||
name: 'description', | ||
content: 'This API is used to generate RGB gradient text for Minecraft', | ||
}, | ||
{ | ||
name: 'og:description', | ||
content: 'This API is used to generate RGB gradient text for Minecraft', | ||
}, | ||
{ | ||
name: 'og:image', | ||
content: '/branding/icon.png', | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { RequestHandler } from '@builder.io/qwik-city'; | ||
|
||
export const onGet: RequestHandler = async ({ json }) => { | ||
throw json(200, { | ||
endpoints: { | ||
'/api/v2/rgb': { | ||
type: 'GET', | ||
description: 'Generate a gradient.', | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { RequestHandler } from '@builder.io/qwik-city'; | ||
import { v3formats } from '~/components/util/PresetUtils'; | ||
import { generateOutput } from '~/components/util/RGBUtils'; | ||
import { rgbDefaults } from '~/routes/resources/rgb'; | ||
|
||
export const onGet: RequestHandler = async ({ json, parseBody }) => { | ||
const body = await parseBody() as any; | ||
const { text, colors, prefixsuffix, trimspaces, bold, italic, underline, strikethrough, silent } = body ?? {}; | ||
|
||
const options = silent ? {} : { | ||
input: { | ||
...rgbDefaults, | ||
...body, | ||
}, | ||
options: { | ||
text: { | ||
type: 'string', | ||
description: 'The text to use for the gradient.', | ||
default: rgbDefaults.text, | ||
}, | ||
colors: { | ||
type: 'array of hex colors', | ||
description: 'The colors to use for the gradient. Must be in hex format.', | ||
default: rgbDefaults.colors, | ||
}, | ||
format: { | ||
type: 'format object - see data models in docs', | ||
description: 'The format to use for the color and format codes. For MiniMessage, { color: "MiniMessage" } can be used.', | ||
default: rgbDefaults.format, | ||
}, | ||
prefixsuffix: { | ||
type: 'string', | ||
description: 'The prefix or suffix to use for the text. Usually used for commands and stuff. $t will be replaced with the output text, if $t is not included, the output will not show.', | ||
default: rgbDefaults.prefixsuffix, | ||
}, | ||
trimspaces: { | ||
type: 'boolean', | ||
description: 'Whether or not to trim color codes from spaces. Turn this off if you\'re using empty underlines or strikethroughs.', | ||
default: rgbDefaults.trimspaces, | ||
}, | ||
bold: { | ||
type: 'boolean', | ||
description: 'Whether or not to bold the text.', | ||
default: rgbDefaults.bold, | ||
}, | ||
italic: { | ||
type: 'boolean', | ||
description: 'Whether or not to italicize the text.', | ||
default: rgbDefaults.italic, | ||
}, | ||
underline: { | ||
type: 'boolean', | ||
description: 'Whether or not to underline the text.', | ||
default: rgbDefaults.underline, | ||
}, | ||
strikethrough: { | ||
type: 'boolean', | ||
description: 'Whether or not to strikethrough the text.', | ||
default: rgbDefaults.strikethrough, | ||
}, | ||
silent: { | ||
type: 'boolean', | ||
description: 'Set this to true to hide the options and input.', | ||
default: false, | ||
}, | ||
}, | ||
}; | ||
|
||
// in case stupid | ||
// mostly just so people can just send { color: "MiniMessage" } | ||
let format = body?.format; | ||
if (format && !format.char && (!format.bold || !format.italic || !format.underline || !format.strikethrough)) { | ||
format = v3formats.find(f => f.color == format.color) ?? { ...format, char: '&' }; | ||
} | ||
|
||
throw json(200, { | ||
output: generateOutput(text, colors, format, prefixsuffix, trimspaces, bold, italic, underline, strikethrough), | ||
...options, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.