forked from external-repos/noisedash
Fix some server logic
This commit is contained in:
@@ -30,7 +30,7 @@ app.use(session({
|
|||||||
resave: true,
|
resave: true,
|
||||||
saveUninitialized: true
|
saveUninitialized: true
|
||||||
}))
|
}))
|
||||||
app.use(function (req, res, next) {
|
app.use((req, res, next) => {
|
||||||
const msgs = req.session.messages || []
|
const msgs = req.session.messages || []
|
||||||
res.locals.messages = msgs
|
res.locals.messages = msgs
|
||||||
res.locals.hasMessages = !!msgs.length
|
res.locals.hasMessages = !!msgs.length
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ router.post('/profiles', (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
profileID = this.lastID
|
profileID = this.lastID
|
||||||
})
|
|
||||||
|
|
||||||
req.body.samples.forEach(s => {
|
req.body.samples.forEach(s => {
|
||||||
db.run('INSERT INTO profiles_samples (profile, sample) VALUES (?, ?)', [
|
db.run('INSERT INTO profiles_samples (profile, sample) VALUES (?, ?)', [
|
||||||
@@ -63,6 +62,13 @@ router.post('/profiles', (req, res) => {
|
|||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
db.run('UPDATE samples SET volume = ? WHERE id = ?', [s.volume, s.id], (err) => {
|
||||||
|
if (err) {
|
||||||
|
return res.sendStatus(500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return res.sendStatus(200)
|
return res.sendStatus(200)
|
||||||
@@ -100,6 +106,7 @@ router.get('/profiles/:profileId', (req, res) => {
|
|||||||
|
|
||||||
const profile = {}
|
const profile = {}
|
||||||
|
|
||||||
|
db.serialize(() => {
|
||||||
db.get(`SELECT
|
db.get(`SELECT
|
||||||
name,
|
name,
|
||||||
user,
|
user,
|
||||||
@@ -142,9 +149,42 @@ router.get('/profiles/:profileId', (req, res) => {
|
|||||||
profile.tremoloFrequency = row.tremoloFrequency
|
profile.tremoloFrequency = row.tremoloFrequency
|
||||||
profile.tremoloDepth = row.tremoloDepth
|
profile.tremoloDepth = row.tremoloDepth
|
||||||
|
|
||||||
|
const sampleIds = []
|
||||||
|
|
||||||
|
db.all('SELECT sample FROM profiles_samples WHERE profile = ?', [req.params.profileId], (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
return res.sendStatus(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
const samples = []
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
sampleIds.push(row.sample)
|
||||||
|
})
|
||||||
|
|
||||||
|
db.all('SELECT id, name, volume FROM samples WHERE id IN ( ' + sampleIds.map(() => { return '?' }).join(',') + ' )', sampleIds, (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
return res.sendStatus(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const sample = {}
|
||||||
|
|
||||||
|
sample.id = row.id
|
||||||
|
sample.name = row.name
|
||||||
|
sample.volume = row.volume
|
||||||
|
|
||||||
|
samples.push(sample)
|
||||||
|
})
|
||||||
|
|
||||||
|
profile.samples = samples
|
||||||
|
|
||||||
res.json({ profile: profile })
|
res.json({ profile: profile })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
router.delete('/profiles/:profileId', (req, res) => {
|
router.delete('/profiles/:profileId', (req, res) => {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
@@ -163,6 +203,12 @@ router.delete('/profiles/:profileId', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
db.run('DELETE FROM profiles WHERE id = ?', [req.params.profileId], (err) => {
|
db.run('DELETE FROM profiles WHERE id = ?', [req.params.profileId], (err) => {
|
||||||
|
if (err) {
|
||||||
|
return res.sendStatus(500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
db.run('DELETE FROM profiles_samples WHERE profile = ?', [req.params.profileId], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -323,18 +323,16 @@
|
|||||||
class="mx-3 mb-5"
|
class="mx-3 mb-5"
|
||||||
v-on="on"
|
v-on="on"
|
||||||
>
|
>
|
||||||
Upload Sample
|
Add Sample
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</template>
|
</template>
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>
|
<v-card-title>
|
||||||
<span class="text-h5">Add a Sample</span>
|
<span class="text-h5">Add Sample</span>
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-divider />
|
||||||
<p><strong>WARNING:</strong> Uploaded samples are publicly accessible.</p>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-file-input
|
<v-file-input
|
||||||
v-model="selectedSample"
|
v-model="selectedSample"
|
||||||
@@ -342,6 +340,11 @@
|
|||||||
label="Upload a sample!"
|
label="Upload a sample!"
|
||||||
/>
|
/>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
<v-row>
|
||||||
|
<v-col cols="12">
|
||||||
|
<p><strong>WARNING:</strong> Uploaded samples are publicly accessible.</p>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
|
|||||||
@@ -219,6 +219,8 @@ export default {
|
|||||||
this.isTremoloEnabled = profile.isTremoloEnabled
|
this.isTremoloEnabled = profile.isTremoloEnabled
|
||||||
this.tremoloFrequency = profile.tremoloFrequency
|
this.tremoloFrequency = profile.tremoloFrequency
|
||||||
this.tremoloDepth = profile.tremoloDepth
|
this.tremoloDepth = profile.tremoloDepth
|
||||||
|
|
||||||
|
this.samples = profile.samples
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user