mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added licence notice to many files, other minor type fixes
This commit is contained in:
parent
d9175c1fc2
commit
75d93af246
22 changed files with 483 additions and 107 deletions
|
@ -1,3 +1,23 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
Question Server
|
||||
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
|
||||
|
||||
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/>.
|
||||
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
export default {
|
||||
ReadFile: ReadFile,
|
||||
ReadJSON: ReadJSON,
|
||||
|
@ -24,7 +44,7 @@ import { Request } from '../types/basicTypes'
|
|||
|
||||
interface URLFormatOptions {
|
||||
pathname?: string
|
||||
query?: any
|
||||
query?: { [key: string]: string }
|
||||
}
|
||||
|
||||
function formatUrl(options: URLFormatOptions): string {
|
||||
|
@ -42,8 +62,11 @@ function formatUrl(options: URLFormatOptions): string {
|
|||
return path + queryString
|
||||
}
|
||||
|
||||
function GetDateString(noTime?: boolean): string {
|
||||
const date = new Date()
|
||||
function GetDateString(
|
||||
referenceDate?: Date | string,
|
||||
noTime?: boolean
|
||||
): string {
|
||||
const date = referenceDate ? new Date(referenceDate) : new Date()
|
||||
|
||||
if (noTime) {
|
||||
return (
|
||||
|
@ -183,7 +206,14 @@ function deleteFile(fname: string): Boolean {
|
|||
return false
|
||||
}
|
||||
|
||||
function uploadFile(req: Request, path: string): Promise<any> {
|
||||
function uploadFile(
|
||||
req: Request,
|
||||
path: string
|
||||
): Promise<{
|
||||
body: Request['body']
|
||||
fileName: string
|
||||
filePath: string
|
||||
}> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (!req.files) {
|
||||
|
@ -235,7 +265,7 @@ function uploadFile(req: Request, path: string): Promise<any> {
|
|||
})
|
||||
}
|
||||
|
||||
function statFile(file: string): any {
|
||||
function statFile(file: string): fs.Stats {
|
||||
if (FileExists(file)) {
|
||||
return fs.statSync(file)
|
||||
} else {
|
||||
|
@ -243,7 +273,7 @@ function statFile(file: string): any {
|
|||
}
|
||||
}
|
||||
|
||||
function renameFile(oldPath: string, newPath: string): any {
|
||||
function renameFile(oldPath: string, newPath: string): string {
|
||||
if (FileExists(oldPath)) {
|
||||
fs.renameSync(oldPath, newPath)
|
||||
return newPath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue