Fix deployment #596

Closed
Irev-Dev wants to merge 4 commits from kurt/fix-deployment into release
17 changed files with 2531 additions and 3297 deletions

View File

@@ -9,7 +9,7 @@
"axios": "^0.21.1", "axios": "^0.21.1",
"cloudinary": "^1.23.0", "cloudinary": "^1.23.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"discord.js": "^13.5.1", "discord.js": "^13.6.0",
"express": "^4.17.1", "express": "^4.17.1",
"human-id": "^2.0.1", "human-id": "^2.0.1",
"middy": "^0.36.0", "middy": "^0.36.0",

View File

@@ -1,6 +1,7 @@
import { createGraphQLHandler } from '@redwoodjs/graphql-server' import { createGraphQLHandler } from '@redwoodjs/graphql-server'
import { createSentryApolloPlugin } from 'src/lib/sentry' import { createSentryApolloPlugin } from 'src/lib/sentry'
import { logger } from 'src/lib/logger' import { logger } from 'src/lib/logger'
import 'discord.js'
import directives from 'src/directives/**/*.{js,ts}' import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}' import sdls from 'src/graphql/**/*.sdl.{js,ts}'

View File

@@ -1,34 +1,40 @@
import {Client, Intents, MessageAttachment} from "discord.js" import { Client, Intents, MessageAttachment } from 'discord.js'
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}) const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
})
export async function sendDiscordMessage(text: string, url?: string) { export async function sendDiscordMessage(text: string, url?: string) {
if (!client.isReady()) { if (!client.isReady()) {
console.error(`Discord: client is not ready to send message ("${text}")`); console.error(`Discord: client is not ready to send message ("${text}")`)
} else { } else {
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID); const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID)
if (url) { if (url) {
channel.send({ embeds: [{ channel.send({
title: text, embeds: [
image: { {
url: url, title: text,
}, image: {
}] }); url: url,
},
},
],
})
} else { } else {
channel.send(text) channel.send(text)
} }
} }
} }
client.on("ready", async () => { client.on('ready', async () => {
console.log(`Discord: logged in as ${client.user.tag}`) console.log(`Discord: logged in as ${client.user.tag}`)
}) })
if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) { if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
console.warn("Discord bot not configured - please set process.env.DISCORD_TOKEN and process.env.DISCORD_CHANNEL_ID to send discord chats"); console.warn(
'Discord bot not configured - please set process.env.DISCORD_TOKEN and process.env.DISCORD_CHANNEL_ID to send discord chats'
)
} else { } else {
console.log(`Discord: logging in (token ${process.env.DISCORD_TOKEN})`); console.log(`Discord: logging in (token ${process.env.DISCORD_TOKEN})`)
client.login(process.env.DISCORD_TOKEN); client.login(process.env.DISCORD_TOKEN)
} }

View File

@@ -14,7 +14,6 @@ import { requireAuth } from 'src/lib/auth'
import { requireOwnership, requireProjectOwnership } from 'src/lib/owner' import { requireOwnership, requireProjectOwnership } from 'src/lib/owner'
import { sendDiscordMessage } from 'src/lib/discord' import { sendDiscordMessage } from 'src/lib/discord'
export const projects = ({ userName }) => { export const projects = ({ userName }) => {
if (!userName) { if (!userName) {
return db.project.findMany({ where: { deleted: false } }) return db.project.findMany({ where: { deleted: false } })
@@ -249,13 +248,16 @@ export const updateProjectImages = async ({
const { userName } = await db.user.findUnique({ const { userName } = await db.user.findUnique({
where: { id: project.userId }, where: { id: project.userId },
}) })
sendDiscordMessage([ sendDiscordMessage(
`${userName} just added an image to their ${project.cadPackage} project:`, [
` => ${project.title}`, `${userName} just added an image to their ${project.cadPackage} project:`,
``, ` => ${project.title}`,
`Check it out, leave a comment, make them feel welcome!`, ``,
`https://cadhub.xyz/u/${userName}/${project.title}` `Check it out, leave a comment, make them feel welcome!`,
].join('\n'), `https://res.cloudinary.com/irevdev/image/upload/c_scale,w_700/v1/${mainImage}`) `https://cadhub.xyz/u/${userName}/${project.title}`,
].join('\n'),
`https://res.cloudinary.com/irevdev/image/upload/c_scale,w_700/v1/${mainImage}`
)
return result return result
}) })
return updatedProject return updatedProject

View File

@@ -2,6 +2,7 @@
command = "yarn rw deploy netlify" command = "yarn rw deploy netlify"
publish = "web/dist" publish = "web/dist"
functions = "api/dist/functions" functions = "api/dist/functions"
ignore = "false"
[dev] [dev]
# To use [Netlify Dev](https://www.netlify.com/products/dev/), # To use [Netlify Dev](https://www.netlify.com/products/dev/),

View File

@@ -36,4 +36,4 @@
"prisma": { "prisma": {
"seed": "yarn rw exec seed" "seed": "yarn rw exec seed"
} }
} }

View File

@@ -1,6 +1,9 @@
import React from 'react' import React from 'react'
import { useRender } from 'src/components/IdeWrapper/useRender' import { useRender } from 'src/components/IdeWrapper/useRender'
import { makeStlDownloadHandler, PullTitleFromFirstLine } from 'src/helpers/download_stl' import {
makeStlDownloadHandler,
PullTitleFromFirstLine,
} from 'src/helpers/download_stl'
import { useSaveCode } from 'src/components/IdeWrapper/useSaveCode' import { useSaveCode } from 'src/components/IdeWrapper/useSaveCode'
import { DropdownItem } from './Dropdowns' import { DropdownItem } from './Dropdowns'
import { useShortcutsModalContext } from './AllShortcutsModal' import { useShortcutsModalContext } from './AllShortcutsModal'

View File

@@ -1,31 +1,30 @@
import Seo from 'src/components/Seo/Seo' import Seo from 'src/components/Seo/Seo'
import IdeViewer from 'src/components/IdeViewer/IdeViewer' import IdeViewer from 'src/components/IdeViewer/IdeViewer'
import { useIdeState } from 'src/helpers/hooks/useIdeState' import { useIdeState } from 'src/helpers/hooks/useIdeState'
import type { Project } from 'src/components/EmbedProjectCell/EmbedProjectCell' import type { Project } from 'src/components/EmbedProjectCell/EmbedProjectCell'
import { IdeContext } from 'src/helpers/hooks/useIdeContext' import { IdeContext } from 'src/helpers/hooks/useIdeContext'
import { use3dViewerResize } from 'src/helpers/hooks/use3dViewerResize' import { use3dViewerResize } from 'src/helpers/hooks/use3dViewerResize'
import { useEffect } from 'react' import { useEffect } from 'react'
interface Props {
interface Props { project?: Project
project?: Project }
}
const EmbedProject = ({ project }: Props) => {
const EmbedProject = ({ project }: Props) => { const [state, thunkDispatch] = useIdeState()
const [state, thunkDispatch] = useIdeState() const { viewerDomRef, handleViewerSizeUpdate } = use3dViewerResize()
const { viewerDomRef, handleViewerSizeUpdate } = use3dViewerResize()
useEffect(() => {
useEffect(() => { handleViewerSizeUpdate()
handleViewerSizeUpdate() }, [])
}, [])
return (
return ( <div className="flex flex-col h-screen" ref={viewerDomRef}>
<div className="flex flex-col h-screen" ref={viewerDomRef} > <IdeContext.Provider value={{ state, thunkDispatch, project }}>
<IdeContext.Provider value={{ state, thunkDispatch, project }}> <IdeViewer />
<IdeViewer /> </IdeContext.Provider>
</IdeContext.Provider> </div>
</div> )
) }
}
export default EmbedProject
export default EmbedProject

View File

@@ -38,10 +38,9 @@ export const Success = ({
}) => { }) => {
const [state, thunkDispatch] = useIdeState() const [state, thunkDispatch] = useIdeState()
return ( return (
<IdeContext.Provider value={{ state, thunkDispatch, project }}> <IdeContext.Provider value={{ state, thunkDispatch, project }}>
<EmbedViewer project={project} /> <EmbedViewer project={project} />
</IdeContext.Provider> </IdeContext.Provider>
) )
} }

View File

@@ -7,28 +7,44 @@ import LogoType from '../LogoType/LogoType'
import { Link, routes } from '@redwoodjs/router' import { Link, routes } from '@redwoodjs/router'
function EmbedViewer() { function EmbedViewer() {
const { state, project } = useIdeContext() const { state, project } = useIdeContext()
useIdeInit(project?.cadPackage, project?.code || state?.code, "viewer") useIdeInit(project?.cadPackage, project?.code || state?.code, 'viewer')
const { viewerDomRef } = use3dViewerResize() const { viewerDomRef } = use3dViewerResize()
return ( return (
<div className="relative flex flex-col h-screen group" ref={viewerDomRef}> <div className="relative flex flex-col h-screen group" ref={viewerDomRef}>
<IdeViewer isMinimal={true} /> <IdeViewer isMinimal={true} />
<div className="absolute top-5 left-5 text-ch-gray-300"> <div className="absolute top-5 left-5 text-ch-gray-300">
<h1 className="mb-4 text-4xl font-normal capitalize "> <h1 className="mb-4 text-4xl font-normal capitalize ">
{project?.title.replace(/-/g, ' ')} {project?.title.replace(/-/g, ' ')}
</h1> </h1>
<h2 className="mb-2 transition-opacity duration-100 group-hover:opacity-0">by @{ project?.user?.userName }</h2> <h2 className="mb-2 transition-opacity duration-100 group-hover:opacity-0">
<h2 className="transition-opacity duration-100 group-hover:opacity-0">built with <div className="inline-block"><CadPackage cadPackage={project?.cadPackage} className="px-3 py-2"/></div></h2> by @{project?.user?.userName}
</div> </h2>
<div className="absolute grid items-center grid-flow-col-dense gap-2 bottom-5 right-5 text-ch-gray-300"> <h2 className="transition-opacity duration-100 group-hover:opacity-0">
View on <Link className="inline-block" to={routes.project({ built with{' '}
userName: project?.user?.userName, <div className="inline-block">
projectTitle: project?.title.toString(), <CadPackage
})}><LogoType className="inline-block" wrappedInLink={true}/></Link> cadPackage={project?.cadPackage}
</div> className="px-3 py-2"
</div> />
) </div>
</h2>
</div>
<div className="absolute grid items-center grid-flow-col-dense gap-2 bottom-5 right-5 text-ch-gray-300">
View on{' '}
<Link
className="inline-block"
to={routes.project({
userName: project?.user?.userName,
projectTitle: project?.title.toString(),
})}
>
<LogoType className="inline-block" wrappedInLink={true} />
</Link>
</div>
</div>
)
} }
export default EmbedViewer export default EmbedViewer

View File

@@ -6,8 +6,8 @@ const IdeViewer = ({
handleOwnCamera = false, handleOwnCamera = false,
isMinimal = false, isMinimal = false,
}: { }: {
handleOwnCamera?: boolean, handleOwnCamera?: boolean
isMinimal?: boolean, isMinimal?: boolean
}) => { }) => {
const { state, thunkDispatch } = useIdeContext() const { state, thunkDispatch } = useIdeContext()
const dataType = state.objectData?.type const dataType = state.objectData?.type
@@ -43,7 +43,7 @@ const IdeViewer = ({
} }
}) })
} }
return ( return (
<PureIdeViewer <PureIdeViewer
dataType={dataType} dataType={dataType}

View File

@@ -2,42 +2,43 @@ import Tooltip from '@material-ui/core/Tooltip'
import { Link, routes } from '@redwoodjs/router' import { Link, routes } from '@redwoodjs/router'
import Svg from 'src/components/Svg' import Svg from 'src/components/Svg'
export default function LogoType({ className="", wrappedInLink=false }) { export default function LogoType({ className = '', wrappedInLink = false }) {
return ( return (
<ul className={"flex items-center " + className}> <ul className={'flex items-center ' + className}>
<li> <li>
{ (wrappedInLink {wrappedInLink ? (
? <Link to={routes.home()}> <Link to={routes.home()}>
<div className="ml-2 overflow-hidden rounded-full"> <div className="ml-2 overflow-hidden rounded-full">
<Svg className="w-10" name="favicon" /> <Svg className="w-10" name="favicon" />
</div> </div>
</Link> </Link>
: <div> ) : (
<div className="ml-2 overflow-hidden rounded-full"> <div>
<Svg className="w-10" name="favicon" /> <div className="ml-2 overflow-hidden rounded-full">
</div> <Svg className="w-10" name="favicon" />
</div> </div>
)} </div>
</li> )}
<li> </li>
<Tooltip title="Very alpha, there's lots of work todo"> <li>
<div className="flex ml-4"> <Tooltip title="Very alpha, there's lots of work todo">
{/* Because of how specific these styles are to this heading/logo and it doesn't need to be replicated else where as well as it's very precise with the placement of "pre-alpha" I think it's appropriate. */} <div className="flex ml-4">
<h2 {/* Because of how specific these styles are to this heading/logo and it doesn't need to be replicated else where as well as it's very precise with the placement of "pre-alpha" I think it's appropriate. */}
className="py-1 text-2xl text-indigo-300 md:text-5xl font-ropa-sans md:tracking-wider" <h2
style={{ letterSpacing: '0.3em' }} className="py-1 text-2xl text-indigo-300 md:text-5xl font-ropa-sans md:tracking-wider"
> style={{ letterSpacing: '0.3em' }}
CadHub >
</h2> CadHub
<div </h2>
className="hidden text-sm font-bold text-pink-400 font-ropa-sans md:block" <div
style={{ paddingBottom: '2rem', marginLeft: '-1.8rem' }} className="hidden text-sm font-bold text-pink-400 font-ropa-sans md:block"
> style={{ paddingBottom: '2rem', marginLeft: '-1.8rem' }}
pre-alpha >
</div> pre-alpha
</div> </div>
</Tooltip> </div>
</li> </Tooltip>
</ul> </li>
) </ul>
} )
}

View File

@@ -194,13 +194,13 @@ export const Success = ({ userProject, refetch }) => {
}) })
const onStlDownload = makeStlDownloadHandler({ const onStlDownload = makeStlDownloadHandler({
type: state.objectData?.type, type: state.objectData?.type,
ideType: state.ideType, ideType: state.ideType,
geometry: state.objectData?.data, geometry: state.objectData?.data,
quality: state.objectData?.quality, quality: state.objectData?.quality,
fileName: `${userProject.Project.title }.stl`, fileName: `${userProject.Project.title}.stl`,
thunkDispatch, thunkDispatch,
}) })
return ( return (
<IdeContext.Provider <IdeContext.Provider

View File

@@ -103,7 +103,7 @@ const ProjectProfile = ({
<Button <Button
className={getActiveClasses( className={getActiveClasses(
'ml-3 hover:bg-opacity-100 bg-ch-pink-800 bg-opacity-30 mt-4 mb-3 text-ch-gray-300', 'ml-3 hover:bg-opacity-100 bg-ch-pink-800 bg-opacity-30 mt-4 mb-3 text-ch-gray-300',
{ 'bg-indigo-200': currentUser } { 'bg-indigo-200': currentUser }
)} )}
shouldAnimateHover shouldAnimateHover
iconName={'document-download'} iconName={'document-download'}

View File

@@ -3,19 +3,24 @@ import { useIdeContext } from 'src/helpers/hooks/useIdeContext'
const StaticImageMessage = () => { const StaticImageMessage = () => {
const { state } = useIdeContext() const { state } = useIdeContext()
if ((state.ideType !== 'openscad' && state.ideType !== 'curv') || state.objectData?.type !== 'png') { if (
(state.ideType !== 'openscad' && state.ideType !== 'curv') ||
state.objectData?.type !== 'png'
) {
return null return null
} }
return state.ideType === 'openscad' ? return state.ideType === 'openscad' ? (
<OutBound <OutBound
to="https://learn.cadhub.xyz/docs/general-cadhub/openscad-previews" to="https://learn.cadhub.xyz/docs/general-cadhub/openscad-previews"
className="text-ch-gray-300 border-ch-gray-300 rounded-md mr-12 px-2 py-1 text-xs" className="text-ch-gray-300 border-ch-gray-300 rounded-md mr-12 px-2 py-1 text-xs"
> >
Why reload each camera move? Why reload each camera move?
</OutBound> </OutBound>
: <div className="text-ch-gray-300 border-ch-gray-300 rounded-md mr-12 px-2 py-1 text-xs"> ) : (
Alpha Curv integration, no camera support currently. <div className="text-ch-gray-300 border-ch-gray-300 rounded-md mr-12 px-2 py-1 text-xs">
</div> Alpha Curv integration, no camera support currently.
</div>
)
} }
export default StaticImageMessage export default StaticImageMessage

View File

@@ -318,9 +318,11 @@ const makeScriptWorker = ({ callback, convertToSolids }) => {
let onInit, main, scriptStats, entities, lastParamsDef let onInit, main, scriptStats, entities, lastParamsDef
function runMain(params = {}) { function runMain(params = {}) {
if(lastParamsDef) lastParamsDef.forEach(def=>{ if (lastParamsDef)
if(!(def.name in params) && 'initial' in def) params[def.name] = def.initial lastParamsDef.forEach((def) => {
}) if (!(def.name in params) && 'initial' in def)
params[def.name] = def.initial
})
let time = Date.now() let time = Date.now()
let solids let solids
const transfer = [] const transfer = []

File diff suppressed because it is too large Load Diff