Remove sounds (#8617)
* feat: remove sounds * feat: remove more sounds * feat: disable sounds plugin * fix: openapiv1.18.x
parent
251ea79bd2
commit
5f10d67db5
@ -1,21 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('admin/settings/sounds', ['sounds', 'settings', 'admin/settings'], function (Sounds, Settings, AdminSettings) {
|
||||
var SoundsAdmin = {};
|
||||
|
||||
SoundsAdmin.init = function () {
|
||||
// Sounds tab
|
||||
$('.sounds').find('button[data-action="play"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var soundName = $(this).parent().parent().find('select')
|
||||
.val();
|
||||
Sounds.playSound(soundName);
|
||||
});
|
||||
|
||||
AdminSettings.prepare();
|
||||
};
|
||||
|
||||
return SoundsAdmin;
|
||||
});
|
@ -1,95 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('sounds', ['storage'], function (storage) {
|
||||
var Sounds = {};
|
||||
|
||||
var fileMap;
|
||||
var soundMap;
|
||||
var cache = {};
|
||||
|
||||
Sounds.loadMap = function loadMap(callback) {
|
||||
socket.emit('modules.sounds.getUserSoundMap', function (err, map) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
soundMap = map;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function loadData(callback) {
|
||||
var outstanding = 2;
|
||||
function after() {
|
||||
outstanding -= 1;
|
||||
if (outstanding === 0 && callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
if (fileMap) {
|
||||
outstanding -= 1;
|
||||
} else {
|
||||
$.getJSON(config.relative_path + '/assets/sounds/fileMap.json', function (map) {
|
||||
fileMap = map;
|
||||
after();
|
||||
});
|
||||
}
|
||||
|
||||
Sounds.loadMap(after);
|
||||
}
|
||||
|
||||
Sounds.playSound = function playSound(soundName) {
|
||||
if (!soundMap || !fileMap) {
|
||||
return loadData(after);
|
||||
}
|
||||
|
||||
function after() {
|
||||
if (!fileMap[soundName]) {
|
||||
return;
|
||||
}
|
||||
var audio = cache[soundName] || new Audio(config.relative_path + '/assets/sounds/' + fileMap[soundName]);
|
||||
cache[soundName] = audio;
|
||||
audio.pause();
|
||||
audio.currentTime = 0;
|
||||
audio.play();
|
||||
}
|
||||
|
||||
after();
|
||||
};
|
||||
|
||||
Sounds.play = function play(type, id) {
|
||||
function after() {
|
||||
if (!soundMap[type]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (id) {
|
||||
var item = 'sounds.handled:' + id;
|
||||
if (storage.getItem(item)) {
|
||||
return;
|
||||
}
|
||||
storage.setItem(item, true);
|
||||
|
||||
setTimeout(function () {
|
||||
storage.removeItem(item);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
Sounds.playSound(soundMap[type]);
|
||||
}
|
||||
|
||||
if (!soundMap || !fileMap) {
|
||||
return loadData(after);
|
||||
}
|
||||
|
||||
after();
|
||||
};
|
||||
|
||||
socket.on('event:sounds.reloadMapping', function () {
|
||||
Sounds.loadMap();
|
||||
});
|
||||
|
||||
return Sounds;
|
||||
});
|
@ -1,101 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
let mkdirp = require('mkdirp');
|
||||
mkdirp = mkdirp.hasOwnProperty('native') ? mkdirp : util.promisify(mkdirp);
|
||||
|
||||
const rimraf = require('rimraf');
|
||||
const rimrafAsync = util.promisify(rimraf);
|
||||
|
||||
const file = require('../file');
|
||||
const plugins = require('../plugins');
|
||||
const user = require('../user');
|
||||
const Meta = require('./index');
|
||||
|
||||
const soundsPath = path.join(__dirname, '../../build/public/sounds');
|
||||
const uploadsPath = path.join(__dirname, '../../public/uploads/sounds');
|
||||
|
||||
const Sounds = module.exports;
|
||||
|
||||
Sounds.addUploads = async function addUploads() {
|
||||
let files = [];
|
||||
try {
|
||||
files = await fs.promises.readdir(uploadsPath);
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
files = [];
|
||||
}
|
||||
|
||||
var uploadSounds = files.reduce(function (prev, fileName) {
|
||||
var name = fileName.split('.');
|
||||
if (!name.length || !name[0].length) {
|
||||
return prev;
|
||||
}
|
||||
name = name[0];
|
||||
name = name[0].toUpperCase() + name.slice(1);
|
||||
|
||||
prev[name] = fileName;
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
plugins.soundpacks = plugins.soundpacks.filter(pack => pack.name !== 'Uploads');
|
||||
|
||||
if (Object.keys(uploadSounds).length) {
|
||||
plugins.soundpacks.push({
|
||||
name: 'Uploads',
|
||||
id: 'uploads',
|
||||
dir: uploadsPath,
|
||||
sounds: uploadSounds,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Sounds.build = async function build() {
|
||||
await Sounds.addUploads();
|
||||
|
||||
var map = plugins.soundpacks.map(function (pack) {
|
||||
return Object.keys(pack.sounds).reduce(function (prev, soundName) {
|
||||
var soundPath = pack.sounds[soundName];
|
||||
prev[pack.name + ' | ' + soundName] = pack.id + '/' + soundPath;
|
||||
return prev;
|
||||
}, {});
|
||||
});
|
||||
map.unshift({});
|
||||
map = Object.assign.apply(null, map);
|
||||
await rimrafAsync(soundsPath);
|
||||
await mkdirp(soundsPath);
|
||||
|
||||
await fs.promises.writeFile(path.join(soundsPath, 'fileMap.json'), JSON.stringify(map));
|
||||
|
||||
await Promise.all(plugins.soundpacks.map(pack => file.linkDirs(pack.dir, path.join(soundsPath, pack.id), false)));
|
||||
};
|
||||
|
||||
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
|
||||
|
||||
Sounds.getUserSoundMap = async function getUserSoundMap(uid) {
|
||||
const [defaultMapping, userSettings] = await Promise.all([
|
||||
Meta.configs.getFields(keys),
|
||||
user.getSettings(uid),
|
||||
]);
|
||||
|
||||
userSettings.notification = userSettings.notificationSound;
|
||||
userSettings['chat-incoming'] = userSettings.incomingChatSound;
|
||||
userSettings['chat-outgoing'] = userSettings.outgoingChatSound;
|
||||
|
||||
const soundMapping = {};
|
||||
|
||||
keys.forEach(function (key) {
|
||||
if (userSettings[key] || userSettings[key] === '') {
|
||||
soundMapping[key] = userSettings[key] || '';
|
||||
} else {
|
||||
soundMapping[key] = defaultMapping[key] || '';
|
||||
}
|
||||
});
|
||||
|
||||
return soundMapping;
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Disable nodebb-plugin-soundpack-default',
|
||||
timestamp: Date.UTC(2020, 8, 6),
|
||||
method: async function () {
|
||||
await db.sortedSetRemove('plugins:active', 'nodebb-plugin-soundpack-default');
|
||||
},
|
||||
};
|
@ -1,97 +0,0 @@
|
||||
<div class="sounds settings row">
|
||||
<div class="col-xs-12">
|
||||
<form role="form">
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/sounds:notifications]]</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="notification">[[admin/settings/sounds:notifications]]</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="notification" data-field="notification">
|
||||
<option value="">[[user:no-sound]]</option>
|
||||
<!-- BEGIN notification-sound -->
|
||||
<optgroup label="{notification-sound.name}">
|
||||
<!-- BEGIN notification-sound.sounds -->
|
||||
<option value="{notification-sound.sounds.value}" <!-- IF notification-sound.sounds.selected -->selected<!-- ENDIF notification-sound.sounds.selected -->>
|
||||
{notification-sound.sounds.name}
|
||||
</option>
|
||||
<!-- END notification-sound.sounds -->
|
||||
</optgroup>
|
||||
<!-- END notification-sound -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play"><span class="hidden-xs">[[admin/settings/sounds:play-sound]] </span><i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/sounds:chat-messages]]</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="chat-incoming">[[admin/settings/sounds:incoming-message]]</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-incoming" data-field="chat-incoming">
|
||||
<option value="">[[user:no-sound]]</option>
|
||||
<!-- BEGIN chat-incoming-sound -->
|
||||
<optgroup label="{chat-incoming-sound.name}">
|
||||
<!-- BEGIN chat-incoming-sound.sounds -->
|
||||
<option value="{chat-incoming-sound.sounds.value}" <!-- IF chat-incoming-sound.sounds.selected -->selected<!-- ENDIF chat-incoming-sound.sounds.selected -->>
|
||||
{chat-incoming-sound.sounds.name}
|
||||
</option>
|
||||
<!-- END chat-incoming-sound.sounds -->
|
||||
</optgroup>
|
||||
<!-- END chat-incoming-sound -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play"><span class="hidden-xs">[[admin/settings/sounds:play-sound]] </span><i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="chat-outgoing">[[admin/settings/sounds:outgoing-message]]</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-outgoing" data-field="chat-outgoing">
|
||||
<option value="">[[user:no-sound]]</option>
|
||||
<!-- BEGIN chat-outgoing-sound -->
|
||||
<optgroup label="{chat-outgoing-sound.name}">
|
||||
<!-- BEGIN chat-outgoing-sound.sounds -->
|
||||
<option value="{chat-outgoing-sound.sounds.value}" <!-- IF chat-outgoing-sound.sounds.selected -->selected<!-- ENDIF chat-outgoing-sound.sounds.selected -->>
|
||||
{chat-outgoing-sound.sounds.name}
|
||||
</option>
|
||||
<!-- END chat-outgoing-sound.sounds -->
|
||||
</optgroup>
|
||||
<!-- END chat-outgoing-sound -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play"><span class="hidden-xs">[[admin/settings/sounds:play-sound]] </span><i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<span class="input-group-btn">
|
||||
<input
|
||||
data-action="upload"
|
||||
data-title="Upload Sound"
|
||||
data-route="{config.relative_path}/api/admin/upload/sound"
|
||||
data-accept="audio/*"
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
value="[[admin/settings/sounds:upload-new-sound]]"
|
||||
></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<button id="save" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">
|
||||
<i class="material-icons">save</i>
|
||||
</button>
|
Loading…
Reference in New Issue