i-have-your-ip-address/src/index.ts

64 lines
3.8 KiB
TypeScript
Raw Permalink Normal View History

2021-08-25 20:06:46 +00:00
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
2021-08-25 17:55:19 +00:00
import Express from 'express';
2021-08-25 19:23:28 +00:00
import fs from 'fs';
2021-08-25 17:55:19 +00:00
import path from 'path';
2021-08-25 19:23:28 +00:00
import makeVideo from './ffmpeg';
2021-08-25 17:55:19 +00:00
2021-08-25 19:23:28 +00:00
let p = path.join(__dirname, '..', 'tmp');
if (!fs.existsSync(p)) fs.mkdirSync(p);
2021-08-25 17:55:19 +00:00
2021-08-25 19:23:28 +00:00
const app = Express();
2021-08-25 17:55:19 +00:00
2021-08-25 19:23:28 +00:00
app.get('/', async (req, res) => {
let ip = req.header('X-Forwarded-For')?.split(', ')[0] || req.ip;
let filePath = await makeVideo(ip);
res.sendFile(filePath);
2021-08-25 17:55:19 +00:00
});
app.listen(6969);