Merge pull request #387 from Irev-Dev/main

Release 28 June 2021
This commit was merged in pull request #387.
This commit is contained in:
Kurt Hutten
2021-06-28 20:51:55 +10:00
committed by GitHub
10 changed files with 43 additions and 28 deletions

View File

@@ -14,6 +14,8 @@ You'll need to have Docker installed
Because of the way the docker containers to be deployed as lambdas on aws are somewhat specialised for the purpose we're using `docker-compose` to spin one up for each function/endpoint. So we've added a aws-emulation layer
The docker build relies on a git ignored file, the aws-lambda-rie. [Download it](https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.0/aws-lambda-rie), then put it into `app/api/src/docker/common/`. alternatively you can put this download into the DockerFiles by reading the instructions at around line 29 of the DockerFiles (`app/api/src/docker/openscad/Dockerfile` & `app/api/src/docker/cadquery/Dockerfile`). However this will mean slower build times as it will need download this 14mb file every build.
Then cd into this folder `cd api/src/docker` and:
```bash
@@ -26,8 +28,7 @@ After which we'll also spin up a light express server to act as an emulator to t
yarn install
yarn emulate
```
You can now add OPENSCAD_BASE_URL="http://localhost:8080" to you .env file and restart your main dev process (`yarn rw dev`)
comment that line out if you want to go back to using the aws endpoint (and restart the dev process).
You can now add CAD_LAMBDA_BASE_URL="http://localhost:8080" to you .env file and restart your main dev process (`yarn rw dev`) comment that line out if you want to go back to using the aws endpoint (and restart the dev process).
If you change anything in the `api/src/docker/openscad` directory, you will need to stop the docker process and restart it (will be fairly quick if you're only changing the js)

View File

@@ -10,9 +10,10 @@ app.use(cors())
const invocationURL = (port) =>
`http://localhost:${port}/2015-03-31/functions/function/invocations`
app.post('/openscad/preview', async (req, res) => {
const makeRequest = (route, port) => [route, async (req, res) => {
console.log(`making post request to ${port}, ${route}`)
try {
const { data } = await axios.post(invocationURL(5052), {
const { data } = await axios.post(invocationURL(port), {
body: JSON.stringify(req.body),
})
res.status(data.statusCode)
@@ -21,20 +22,11 @@ app.post('/openscad/preview', async (req, res) => {
res.status(500)
res.send()
}
})
app.post('/cadquery/stl', async (req, res) => {
console.log('making post request to 5060')
try {
const { data } = await axios.post(invocationURL(5060), {
body: JSON.stringify(req.body),
})
res.status(data.statusCode)
res.send(data.body)
} catch (e) {
res.status(500)
res.send()
}
})
}]
app.post(...makeRequest('/openscad/preview', 5052))
app.post(...makeRequest('/openscad/stl', 5053))
app.post(...makeRequest('/cadquery/stl', 5060))
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)

View File

@@ -37,7 +37,7 @@ RUN npm install
# Get the distribution copy of cq-cli
RUN apt-get install -y libglew2.1
RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.2-beta.1/cq-cli-Linux-x86_64.zip
RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.2-beta.2/cq-cli-Linux-x86_64.zip
# Comment the entry above out and uncomment the one below to revert to the stable release
# RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.1.0/cq-cli-Linux-x86_64.zip
RUN unzip cq-cli-Linux-x86_64.zip

View File

@@ -1,10 +1,12 @@
const { makeFile, runCommand } = require('../common/utils')
const { nanoid } = require('nanoid')
module.exports.runCQ = async ({ file, settings = {} } = {}) => {
module.exports.runCQ = async ({ file, settings: {
deflection = 0.3
} = {} } = {}) => {
const tempFile = await makeFile(file, '.py', nanoid)
const fullPath = `/tmp/${tempFile}/output.stl`
const command = `cq-cli/cq-cli --codec stl --infile /tmp/${tempFile}/main.py --outfile ${fullPath}`
const command = `cq-cli/cq-cli --codec stl --infile /tmp/${tempFile}/main.py --outfile ${fullPath} --outputopts "deflection:${deflection};angularDeflection:${deflection};"`
console.log('command', command)
try {

View File

@@ -77,13 +77,17 @@ export const updatePart = async ({ id, input }) => {
}
const originalPart = await db.part.findUnique({ where: { id } })
const imageToDestroy =
originalPart.mainImage !== input.mainImage && input.mainImage && originalPart.mainImage
originalPart.mainImage !== input.mainImage &&
input.mainImage &&
originalPart.mainImage
const update = await db.part.update({
data: foreignKeyReplacement(input),
where: { id },
})
if (imageToDestroy) {
console.log(`image destroyed, publicId: ${imageToDestroy}, partId: ${id}, replacing image is ${input.mainImage}`)
console.log(
`image destroyed, publicId: ${imageToDestroy}, partId: ${id}, replacing image is ${input.mainImage}`
)
// destroy after the db has been updated
destroyImage({ publicId: imageToDestroy })
}

View File

@@ -14,6 +14,12 @@ const Footer = () => {
>
Road Map
</OutBound>
<OutBound
className="mr-8"
to="https://learn.cadhub.xyz/blog"
>
Blog
</OutBound>
<Link className="mr-8" to={routes.codeOfConduct()}>
Code of Conduct
</Link>

View File

@@ -10,6 +10,11 @@ import {
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { Vector3 } from 'three'
import { requestRender } from 'src/helpers/hooks/useIdeState'
import texture from './dullFrontLitMetal.png'
import { TextureLoader } from 'three/src/loaders/TextureLoader'
const loader = new TextureLoader
const colorMap = loader.load(texture)
extend({ OrbitControls })
@@ -22,7 +27,7 @@ function Asset({ geometry: incomingGeo }) {
return (
<mesh ref={mesh} scale={[1, 1, 1]}>
<bufferGeometry attach="geometry" ref={ref} />
<meshStandardMaterial color="#F472B6" />
<meshStandardMaterial map={colorMap} color="#F472B6" />
</mesh>
)
}
@@ -193,8 +198,10 @@ const IdeViewer = ({ Loading }) => {
})
}}
/>
<ambientLight />
<pointLight position={[15, 5, 10]} />
<ambientLight intensity={1} />
<pointLight position={[15, 5, 10]} intensity={4} />
<pointLight position={[-1000, -1000, -1000]} intensity={1}/>
<pointLight position={[-1000, 0, 1000]} intensity={1}/>
{state.objectData?.type === 'png' && (
<>
<Sphere position={[0, 0, 0]} color={pink400} />

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

View File

@@ -27,7 +27,8 @@ const PartProfile = ({
const [isInvalid, setIsInvalid] = useState(false)
const { currentUser } = useAuth()
const editorRef = useRef(null)
const canEdit = currentUser?.sub === userPart.id || currentUser?.roles.includes('admin')
const canEdit =
currentUser?.sub === userPart.id || currentUser?.roles.includes('admin')
const isImageEditable = !isEditable && canEdit // image is editable when not in profile edit mode in order to separate them as it's too hard too to upload an image to cloudinary temporarily until the use saves (and maybe have to clean up) for the time being
const part = userPart?.Part
const emotes = countEmotes(part?.Reaction)

View File

@@ -8,7 +8,9 @@ import {
export const render = async ({ code }) => {
const body = JSON.stringify({
settings: {},
settings: {
deflection: 0.2
},
file: code,
})
try {