forked from external-repos/noisedash
Start edit sample implementation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const db = require('../db')
|
||||
const logger = require('../logger')
|
||||
|
||||
module.exports = function () {
|
||||
db.serialize(() => {
|
||||
@@ -51,5 +52,23 @@ module.exports = function () {
|
||||
FOREIGN KEY(profile) REFERENCES profiles(id),
|
||||
FOREIGN KEY(sample) REFERENCES samples(id))`
|
||||
)
|
||||
|
||||
db.get('PRAGMA user_version', (err, row) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
} else {
|
||||
const userVersion = row.user_version
|
||||
|
||||
if (userVersion === 0) {
|
||||
db.run('ALTER TABLE samples ADD COLUMN fade_in REAL DEFAULT 0')
|
||||
db.run('ALTER TABLE samples ADD COLUMN fade_out REAL DEFAULT 0')
|
||||
db.run('ALTER TABLE samples ADD COLUMN loop_points_enabled INTEGER DEFAULT 0')
|
||||
db.run('ALTER TABLE samples ADD COLUMN loop_start REAL DEFAULT 0')
|
||||
db.run('ALTER TABLE samples ADD COLUMN loop_end REAL DEFAULT 0')
|
||||
|
||||
db.run('PRAGMA user_version = 1')
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,7 +77,15 @@ router.get('/samples', (req, res) => {
|
||||
|
||||
const samples = []
|
||||
|
||||
db.all('SELECT id, name FROM samples WHERE user = ?', [req.user.id], (err, rows) => {
|
||||
db.all(`SELECT
|
||||
id,
|
||||
name,
|
||||
fade_in as fadeIn,
|
||||
fade_out as fadeOut,
|
||||
loop_points_enabled as loopPointsEnabled,
|
||||
loop_start as loopStart,
|
||||
loop_end as loopEnd
|
||||
FROM samples WHERE user = ?`, [req.user.id], (err, rows) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
return res.sendStatus(500)
|
||||
@@ -88,6 +96,11 @@ router.get('/samples', (req, res) => {
|
||||
|
||||
sample.id = row.id
|
||||
sample.name = row.name
|
||||
sample.fadeIn = row.fadeIn
|
||||
sample.fadeOut = row.fadeOut
|
||||
sample.loopPointsEnabled = row.loopPointsEnabled === 1
|
||||
sample.loopStart = row.loopStart
|
||||
sample.loopEnd = row.loopEnd
|
||||
sample.user = req.user.id
|
||||
|
||||
samples.push(sample)
|
||||
@@ -97,4 +110,38 @@ router.get('/samples', (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/samples/:sampleId', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.get(`SELECT
|
||||
id,
|
||||
name,
|
||||
fade_in as fadeIn,
|
||||
fade_out as fadeOut,
|
||||
loop_points_enabled as loopPointsEnabled,
|
||||
loop_start as loopStart,
|
||||
loop_end as loopEnd
|
||||
FROM samples WHERE user = ? AND id = ?`, [req.user.id, req.params.sampleId], (err, row) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
||||
const sample = {}
|
||||
|
||||
sample.id = row.id
|
||||
sample.name = row.name
|
||||
sample.fadeIn = row.fadeIn
|
||||
sample.fadeOut = row.fadeOut
|
||||
sample.loopPointsEnabled = row.loopPointsEnabled === 1
|
||||
sample.loopStart = row.loopStart
|
||||
sample.loopEnd = row.loopEnd
|
||||
sample.user = req.user.id
|
||||
|
||||
res.json({ sample: sample })
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user