lint
This commit is contained in:
parent
9032738ae8
commit
bb2058a010
|
@ -77,7 +77,6 @@
|
||||||
"mustache": "^4.0.1",
|
"mustache": "^4.0.1",
|
||||||
"posthog-js": "1.3.1",
|
"posthog-js": "1.3.1",
|
||||||
"shortid": "^2.2.15",
|
"shortid": "^2.2.15",
|
||||||
"svelte-filepond": "^0.0.1",
|
|
||||||
"svelte-loading-spinners": "^0.1.1",
|
"svelte-loading-spinners": "^0.1.1",
|
||||||
"svelte-portal": "^0.1.0",
|
"svelte-portal": "^0.1.0",
|
||||||
"svelte-simple-modal": "^0.4.2",
|
"svelte-simple-modal": "^0.4.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const apiCall = method => async (
|
const apiCall = method => async (
|
||||||
url,
|
url,
|
||||||
body,
|
body,
|
||||||
headers = { "Content-Type": "application/json" }
|
headers = { "Content-Type": "application/json" }
|
||||||
) => {
|
) => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
|
|
@ -36,9 +36,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeFile() {
|
async function removeFile() {
|
||||||
const response = await api.delete(`/api/attachments/${selectedImage.fileName}`)
|
const response = await api.delete(
|
||||||
|
`/api/attachments/${selectedImage.fileName}`
|
||||||
|
)
|
||||||
files.splice(selectedImageIdx, 1)
|
files.splice(selectedImageIdx, 1)
|
||||||
files = files
|
files = files
|
||||||
|
selectedImageIdx = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigateLeft() {
|
function navigateLeft() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { Circle } from "svelte-loading-spinners"
|
import { Circle } from "svelte-loading-spinners"
|
||||||
|
|
||||||
export let size = "60"
|
export let size = "60"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="file-list">
|
<div class="file-list">
|
||||||
{#each files as file}
|
{#each files as file}
|
||||||
<div class="file">
|
<div class="file">
|
||||||
{#if FILE_TYPES.IMAGE.includes(file.extension)}
|
{#if FILE_TYPES.IMAGE.includes(file.extension)}
|
||||||
<img {width} {height} src={file.clientUrl} />
|
<img {width} {height} src={file.clientUrl} />
|
||||||
{:else}
|
{:else}
|
||||||
<i class="ri-file-line" />
|
<i class="ri-file-line" />
|
||||||
<span class="extension">.{file.extension}</span>
|
<span class="extension">.{file.extension}</span>
|
||||||
<span>{file.name}</span>
|
<span>{file.name}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
grid-gap: var(--spacing-m);
|
grid-gap: var(--spacing-m);
|
||||||
grid-template-columns: repeat(10, 1fr);
|
grid-template-columns: repeat(10, 1fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
backendUiStore.update(state => {
|
backendUiStore.update(state => {
|
||||||
state.selectedView = state.selectedView
|
state.selectedView = state.selectedView
|
||||||
onClosed()
|
onClosed()
|
||||||
notifier.success("Record created successfully.")
|
notifier.success("Record saved successfully.")
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
export let meta
|
export let meta
|
||||||
export let value = meta.type === "boolean" ? false : ""
|
export let value = meta.type === "boolean" ? false : ""
|
||||||
|
export let saveRecord
|
||||||
|
|
||||||
let isSelect =
|
let isSelect =
|
||||||
meta.type === "string" &&
|
meta.type === "string" &&
|
||||||
|
@ -24,7 +25,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInput = event => {
|
const handleInput = event => {
|
||||||
console.log(event.target.value)
|
|
||||||
if (event.target.type === "checkbox") {
|
if (event.target.type === "checkbox") {
|
||||||
value = event.target.checked
|
value = event.target.checked
|
||||||
return
|
return
|
||||||
|
@ -35,12 +35,6 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (event.target.type === "file") {
|
|
||||||
// value = Array.from(event.target.files).map(file => file.path)
|
|
||||||
// console.log(value)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
value = event.target.value
|
value = event.target.value
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -74,5 +74,5 @@ export const FIELDS = {
|
||||||
export const FILE_TYPES = {
|
export const FILE_TYPES = {
|
||||||
IMAGE: ["png", "tiff", "gif", "raw", "jpg", "jpeg"],
|
IMAGE: ["png", "tiff", "gif", "raw", "jpg", "jpeg"],
|
||||||
CODE: ["js", "rs", "py", "java", "rb", "hs", "yml"],
|
CODE: ["js", "rs", "py", "java", "rb", "hs", "yml"],
|
||||||
DOCUMENT: ["odf", "docx", "doc", "pdf", "csv"]
|
DOCUMENT: ["odf", "docx", "doc", "pdf", "csv"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,9 @@
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<img src="/_builder/assets/deploy-rocket.jpg" alt="Rocket flying through sky"/>
|
<img
|
||||||
|
src="/_builder/assets/deploy-rocket.jpg"
|
||||||
|
alt="Rocket flying through sky" />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -110,7 +110,7 @@ exports.uploadAppAssets = async function({
|
||||||
filePath,
|
filePath,
|
||||||
s3Key: filePath.replace(appAssetsPath, `assets/${appId}`),
|
s3Key: filePath.replace(appAssetsPath, `assets/${appId}`),
|
||||||
s3,
|
s3,
|
||||||
metadata: { accountId }
|
metadata: { accountId },
|
||||||
})
|
})
|
||||||
uploads.push(appAssetUpload)
|
uploads.push(appAssetUpload)
|
||||||
})
|
})
|
||||||
|
@ -123,20 +123,20 @@ exports.uploadAppAssets = async function({
|
||||||
for (let file of fileUploads.uploads) {
|
for (let file of fileUploads.uploads) {
|
||||||
if (file.uploaded) continue
|
if (file.uploaded) continue
|
||||||
|
|
||||||
const attachmentUpload = prepareUploadForS3({
|
const attachmentUpload = prepareUploadForS3({
|
||||||
filePath: file.path,
|
filePath: file.path,
|
||||||
s3Key: `assets/${appId}/attachments/${file.name}`,
|
s3Key: `assets/${appId}/attachments/${file.name}`,
|
||||||
s3,
|
s3,
|
||||||
metadata: { accountId }
|
metadata: { accountId },
|
||||||
})
|
})
|
||||||
|
|
||||||
uploads.push(attachmentUpload)
|
uploads.push(attachmentUpload)
|
||||||
|
|
||||||
// mark file as uploaded
|
// mark file as uploaded
|
||||||
file.uploaded = true
|
file.uploaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
db.put(fileUploads);
|
db.put(fileUploads)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
const send = require("koa-send")
|
const send = require("koa-send")
|
||||||
const { resolve, join } = require("path")
|
const { resolve, join } = require("path")
|
||||||
const {
|
|
||||||
budibaseAppsDir,
|
|
||||||
budibaseTempDir,
|
|
||||||
} = require("../../../utilities/budibaseDir")
|
|
||||||
const CouchDB = require("../../../db")
|
|
||||||
const setBuilderToken = require("../../../utilities/builder/setBuilderToken")
|
|
||||||
const { ANON_LEVEL_ID } = require("../../../utilities/accessLevels")
|
|
||||||
const jwt = require("jsonwebtoken")
|
const jwt = require("jsonwebtoken")
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
const fileProcessor = require("./fileProcessor")
|
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const uuid = require("uuid")
|
const uuid = require("uuid")
|
||||||
|
|
||||||
|
const {
|
||||||
|
budibaseAppsDir,
|
||||||
|
budibaseTempDir,
|
||||||
|
} = require("../../utilities/budibaseDir")
|
||||||
|
const CouchDB = require("../../db")
|
||||||
|
const setBuilderToken = require("../../utilities/builder/setBuilderToken")
|
||||||
|
const { ANON_LEVEL_ID } = require("../../utilities/accessLevels")
|
||||||
|
const fileProcessor = require("../../utilities/fileProcessor")
|
||||||
|
|
||||||
exports.serveBuilder = async function(ctx) {
|
exports.serveBuilder = async function(ctx) {
|
||||||
let builderPath = resolve(__dirname, "../../../../builder")
|
let builderPath = resolve(__dirname, "../../../builder")
|
||||||
if (ctx.file === "index.html") {
|
if (ctx.file === "index.html") {
|
||||||
setBuilderToken(ctx)
|
setBuilderToken(ctx)
|
||||||
}
|
}
|
||||||
|
@ -23,13 +24,14 @@ exports.serveBuilder = async function(ctx) {
|
||||||
|
|
||||||
exports.deleteLocalFileUpload = async function(ctx) {
|
exports.deleteLocalFileUpload = async function(ctx) {
|
||||||
try {
|
try {
|
||||||
const db = new CouchDB(ctx.user.instanceId);
|
const db = new CouchDB(ctx.user.instanceId)
|
||||||
let fileUploads = await db.get("_local/fileuploads")
|
let fileUploads = await db.get("_local/fileuploads")
|
||||||
fileUploads.uploads = fileUploads.uploads.filter(upload => upload.fileName !== ctx.fileName)
|
fileUploads.uploads = fileUploads.uploads.filter(
|
||||||
// TODO: possibly remove the file as well
|
upload => upload.fileName !== ctx.params.fileName
|
||||||
await db.put(fileUploads);
|
)
|
||||||
|
await db.put(fileUploads)
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
message: `${ctx.fileName} deleted.`
|
message: `${ctx.fileName} deleted.`,
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(500, err)
|
ctx.throw(500, err)
|
||||||
|
@ -39,10 +41,15 @@ exports.deleteLocalFileUpload = async function(ctx) {
|
||||||
exports.processLocalFileUpload = async function(ctx) {
|
exports.processLocalFileUpload = async function(ctx) {
|
||||||
const { files } = ctx.request.body
|
const { files } = ctx.request.body
|
||||||
|
|
||||||
const attachmentsPath = resolve(budibaseAppsDir(), ctx.user.appId, "attachments")
|
const attachmentsPath = resolve(
|
||||||
|
budibaseAppsDir(),
|
||||||
|
ctx.user.appId,
|
||||||
|
"attachments"
|
||||||
|
)
|
||||||
|
|
||||||
// create attachments dir if it doesnt exist
|
// create attachments dir if it doesnt exist
|
||||||
!fs.existsSync(attachmentsPath) && fs.mkdirSync(attachmentsPath, { recursive: true })
|
!fs.existsSync(attachmentsPath) &&
|
||||||
|
fs.mkdirSync(attachmentsPath, { recursive: true })
|
||||||
|
|
||||||
const filesToProcess = files.map(file => {
|
const filesToProcess = files.map(file => {
|
||||||
const fileExtension = [...file.path.split(".")].pop()
|
const fileExtension = [...file.path.split(".")].pop()
|
||||||
|
@ -55,35 +62,37 @@ exports.processLocalFileUpload = async function(ctx) {
|
||||||
extension: fileExtension,
|
extension: fileExtension,
|
||||||
outputPath: join(attachmentsPath, fileName),
|
outputPath: join(attachmentsPath, fileName),
|
||||||
clientUrl: join("/attachments", fileName),
|
clientUrl: join("/attachments", fileName),
|
||||||
// productionUrl: `https://cdn.app.budi.live/assets/${appId}/attachments/${fileName}`
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: read the file (into memory first, then we will stream it)
|
const fileProcessOperations = filesToProcess.map(file =>
|
||||||
const fileProcessOperations = filesToProcess.map(file => fileProcessor.process(file))
|
fileProcessor.process(file)
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: get file sizes of images after resize
|
// TODO: get file sizes of images after resize
|
||||||
const responses = await Promise.all(fileProcessOperations);
|
const responses = await Promise.all(fileProcessOperations)
|
||||||
|
|
||||||
let fileUploads
|
let pendingFileUploads
|
||||||
// local document used to track which files need to be uploaded
|
// local document used to track which files need to be uploaded
|
||||||
// db.get throws an error if the document doesn't exist
|
// db.get throws an error if the document doesn't exist
|
||||||
// need to use a promise to default
|
// need to use a promise to default
|
||||||
const db = new CouchDB(ctx.user.instanceId);
|
const db = new CouchDB(ctx.user.instanceId)
|
||||||
await db.get("_local/fileuploads")
|
await db
|
||||||
.then(data => fileUploads = data)
|
.get("_local/fileuploads")
|
||||||
.catch(() => fileUploads = {
|
.then(data => {
|
||||||
_id: "_local/fileuploads",
|
pendingFileUploads = data
|
||||||
uploads: []
|
})
|
||||||
|
.catch(() => {
|
||||||
|
pendingFileUploads = { _id: "_local/fileuploads", uploads: [] }
|
||||||
})
|
})
|
||||||
|
|
||||||
fileUploads.uploads = [...filesToProcess, ...fileUploads.uploads]
|
fileUploads.uploads = [...filesToProcess, ...pendingFileUploads.uploads]
|
||||||
await db.put(fileUploads)
|
await db.put(fileUploads)
|
||||||
|
|
||||||
ctx.body = filesToProcess
|
ctx.body = filesToProcess
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(500, err);
|
ctx.throw(500, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +142,13 @@ exports.serveApp = async function(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.serveAttachment = async function(ctx) {
|
exports.serveAttachment = async function(ctx) {
|
||||||
const appId = ctx.user.appId;
|
const appId = ctx.user.appId
|
||||||
|
|
||||||
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
|
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
|
||||||
|
|
||||||
// Serve from CloudFront
|
// Serve from CloudFront
|
||||||
if (process.env.CLOUD) {
|
if (process.env.CLOUD) {
|
||||||
const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/attachments/${ctx.file}`
|
const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}`
|
||||||
|
|
||||||
const response = await fetch(S3_URL)
|
const response = await fetch(S3_URL)
|
||||||
const body = await response.text()
|
const body = await response.text()
|
|
@ -23,8 +23,16 @@ if (env.NODE_ENV !== "production") {
|
||||||
}
|
}
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/attachments/process", authorized(BUILDER), controller.processLocalFileUpload)
|
.post(
|
||||||
.delete("/api/attachments/:fileName*", authorized(BUILDER), controller.deleteLocalFileUpload)
|
"/api/attachments/process",
|
||||||
|
authorized(BUILDER),
|
||||||
|
controller.processLocalFileUpload
|
||||||
|
)
|
||||||
|
.delete(
|
||||||
|
"/api/attachments/:fileName",
|
||||||
|
authorized(BUILDER),
|
||||||
|
controller.deleteLocalFileUpload
|
||||||
|
)
|
||||||
.get("/componentlibrary", controller.serveComponentLibrary)
|
.get("/componentlibrary", controller.serveComponentLibrary)
|
||||||
.get("/assets/:file*", controller.serveAppAsset)
|
.get("/assets/:file*", controller.serveAppAsset)
|
||||||
.get("/attachments/:file*", controller.serveAttachment)
|
.get("/attachments/:file*", controller.serveAttachment)
|
||||||
|
|
|
@ -38,7 +38,7 @@ async function startApp() {
|
||||||
app.server = require("./app")
|
app.server = require("./app")
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080
|
height: 1080,
|
||||||
})
|
})
|
||||||
win.setTitle(APP_TITLE)
|
win.setTitle(APP_TITLE)
|
||||||
win.loadURL(APP_URL)
|
win.loadURL(APP_URL)
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs")
|
||||||
const sharp = require("sharp");
|
const sharp = require("sharp")
|
||||||
const fsPromises = fs.promises;
|
const fsPromises = fs.promises
|
||||||
|
|
||||||
const FORMATS = {
|
const FORMATS = {
|
||||||
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
|
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
|
||||||
}
|
}
|
||||||
|
|
||||||
function processImage({ path, outputPath }) {
|
function processImage({ path, outputPath }) {
|
||||||
return sharp(path)
|
return sharp(path)
|
||||||
.resize(300)
|
.resize(300)
|
||||||
.toFile(outputPath)
|
.toFile(outputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
function process(file) {
|
function process(file) {
|
||||||
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
||||||
return processImage(file);
|
return processImage(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No processing required
|
// No processing required
|
||||||
return fsPromises.copyFile(file.path, file.outputPath)
|
return fsPromises.copyFile(file.path, file.outputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.process = process
|
exports.process = process
|
Loading…
Reference in New Issue