mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-15 04:38:00 +00:00
Fix some server logic
This commit is contained in:
@@ -30,7 +30,7 @@ app.use(session({
|
||||
resave: true,
|
||||
saveUninitialized: true
|
||||
}))
|
||||
app.use(function (req, res, next) {
|
||||
app.use((req, res, next) => {
|
||||
const msgs = req.session.messages || []
|
||||
res.locals.messages = msgs
|
||||
res.locals.hasMessages = !!msgs.length
|
||||
|
||||
@@ -51,7 +51,6 @@ router.post('/profiles', (req, res) => {
|
||||
}
|
||||
|
||||
profileID = this.lastID
|
||||
})
|
||||
|
||||
req.body.samples.forEach(s => {
|
||||
db.run('INSERT INTO profiles_samples (profile, sample) VALUES (?, ?)', [
|
||||
@@ -63,6 +62,13 @@ router.post('/profiles', (req, res) => {
|
||||
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)
|
||||
@@ -100,6 +106,7 @@ router.get('/profiles/:profileId', (req, res) => {
|
||||
|
||||
const profile = {}
|
||||
|
||||
db.serialize(() => {
|
||||
db.get(`SELECT
|
||||
name,
|
||||
user,
|
||||
@@ -142,8 +149,41 @@ router.get('/profiles/:profileId', (req, res) => {
|
||||
profile.tremoloFrequency = row.tremoloFrequency
|
||||
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 })
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
router.delete('/profiles/:profileId', (req, res) => {
|
||||
@@ -163,6 +203,12 @@ router.delete('/profiles/:profileId', (req, res) => {
|
||||
})
|
||||
|
||||
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) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
|
||||
@@ -323,18 +323,16 @@
|
||||
class="mx-3 mb-5"
|
||||
v-on="on"
|
||||
>
|
||||
Upload Sample
|
||||
Add Sample
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="text-h5">Add a Sample</span>
|
||||
<span class="text-h5">Add Sample</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-container>
|
||||
<v-row>
|
||||
<p><strong>WARNING:</strong> Uploaded samples are publicly accessible.</p>
|
||||
</v-row>
|
||||
<v-divider />
|
||||
<v-row>
|
||||
<v-file-input
|
||||
v-model="selectedSample"
|
||||
@@ -342,6 +340,11 @@
|
||||
label="Upload a sample!"
|
||||
/>
|
||||
</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-col cols="12">
|
||||
<v-text-field
|
||||
|
||||
@@ -219,6 +219,8 @@ export default {
|
||||
this.isTremoloEnabled = profile.isTremoloEnabled
|
||||
this.tremoloFrequency = profile.tremoloFrequency
|
||||
this.tremoloDepth = profile.tremoloDepth
|
||||
|
||||
this.samples = profile.samples
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user