Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
LINAGORA
L
LGS
Labs
voice-web
Commits
62bd3489
Commit
62bd3489
authored
Sep 23, 2017
by
Michael Henretty
Browse files
disallow implicit any on server code
parent
f498c04d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
53 additions
and
39 deletions
+53
-39
server/src/lib/api.ts
server/src/lib/api.ts
+14
-12
server/src/lib/clip.ts
server/src/lib/clip.ts
+4
-4
server/src/lib/db/base-db.ts
server/src/lib/db/base-db.ts
+4
-4
server/src/lib/db/mysql.ts
server/src/lib/db/mysql.ts
+1
-1
server/src/lib/files.ts
server/src/lib/files.ts
+22
-10
server/src/lib/logger.ts
server/src/lib/logger.ts
+4
-4
server/src/lib/responder.ts
server/src/lib/responder.ts
+1
-1
server/src/lib/utility.ts
server/src/lib/utility.ts
+1
-1
server/src/server.ts
server/src/server.ts
+1
-1
server/tsconfig.json
server/tsconfig.json
+1
-1
No files found.
server/src/lib/api.ts
View file @
62bd3489
...
...
@@ -26,7 +26,7 @@ export default class API {
}
private
getRandomSentences
(
count
:
number
):
Promise
<
string
[]
>
{
return
this
.
getSentences
().
then
(
sentences
=>
{
return
this
.
getSentences
().
then
(
(
sentences
:
string
[])
=>
{
let
randoms
=
[];
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
let
distribution
=
Random
.
integer
(
0
,
sentences
.
length
-
1
);
...
...
@@ -37,9 +37,10 @@ export default class API {
});
}
private
getFilesInFolder
(
folderpath
)
{
return
new
Promise
((
res
,
rej
)
=>
{
fs
.
readdir
(
folderpath
,
(
err
,
files
)
=>
{
private
getFilesInFolder
(
folderpath
:
string
)
{
return
new
Promise
((
res
:
(
files
:
string
[])
=>
void
,
rej
:
(
error
:
any
)
=>
void
)
=>
{
fs
.
readdir
(
folderpath
,
(
err
:
any
,
files
:
string
[])
=>
{
if
(
err
)
{
rej
(
err
);
return
;
...
...
@@ -50,11 +51,12 @@ export default class API {
});
}
private
getFileContents
(
filepath
)
{
return
new
Promise
((
res
,
rej
)
=>
{
private
getFileContents
(
filepath
:
string
)
{
return
new
Promise
((
res
:
(
contents
:
string
)
=>
void
,
rej
:
(
error
:
any
)
=>
void
)
=>
{
fs
.
readFile
(
filepath
,
{
contents
:
'
utf8
'
},
(
err
,
data
)
=>
{
},
(
err
:
any
,
data
:
Buffer
)
=>
{
if
(
err
)
{
rej
(
err
);
return
;
...
...
@@ -100,7 +102,7 @@ export default class API {
}
return
this
.
getFilesInFolder
(
this
.
getSentenceFolder
())
.
then
(
files
=>
{
.
then
(
(
files
:
string
[])
=>
{
return
Promise
.
all
(
files
.
map
(
filename
=>
{
// Only parse the top-level text files, not any sub folders.
...
...
@@ -115,8 +117,8 @@ export default class API {
// Chop the array of content strings into an array of sentences.
.
then
((
values
)
=>
{
let
sentences
=
[];
.
then
((
values
:
string
[]
)
=>
{
let
sentences
:
string
[]
=
[];
let
sentenceArrays
=
values
.
map
(
fileContents
=>
{
if
(
!
fileContents
)
{
return
[];
...
...
@@ -131,7 +133,7 @@ export default class API {
console
.
log
(
'
sentences found
'
,
sentences
.
length
);
this
.
sentencesCache
=
sentences
;
})
.
catch
(
err
=>
{
.
catch
(
(
err
:
any
)
=>
{
console
.
error
(
'
could not retrieve sentences
'
,
err
);
});
}
...
...
@@ -144,7 +146,7 @@ export default class API {
this
.
getSentences
().
then
((
sentences
:
String
[])
=>
{
return
this
.
getRandomSentences
(
count
);
}).
then
(
randoms
=>
{
}).
then
(
(
randoms
:
string
[])
=>
{
respond
(
response
,
randoms
.
join
(
'
\n
'
));
}).
catch
((
err
:
any
)
=>
{
console
.
error
(
'
Could not load sentences
'
,
err
);
...
...
server/src/lib/clip.ts
View file @
62bd3489
...
...
@@ -57,13 +57,13 @@ export default class Clip {
let
retrieveParam
=
{
Bucket
:
BUCKET_NAME
,
Key
:
key
};
let
awsResult
=
this
.
s3
.
getObject
(
retrieveParam
);
f
.
pass
(
awsResult
);
},
(
awsResult
)
=>
{
},
(
awsResult
:
any
)
=>
{
let
tmpFile
=
fs
.
createWriteStream
(
tmpFilePath
);
tmpFile
=
awsResult
.
createReadStream
().
pipe
(
tmpFile
);
tmpFile
.
on
(
'
finish
'
,
f
.
wait
());
},
()
=>
{
ms
.
pipe
(
request
,
response
,
tmpFilePath
);
}).
onError
(
err
=>
{
}).
onError
(
(
err
:
any
)
=>
{
console
.
error
(
'
streaming audio error
'
,
err
,
err
.
stack
);
respond
(
response
,
'
Server error, could not fetch audio data.
'
,
500
);
});
...
...
@@ -273,14 +273,14 @@ export default class Clip {
// If we were given base64, we'll need to concat it all first
// So we can decode it in the next step.
if
(
contentType
.
includes
(
'
base64
'
))
{
let
chunks
=
[];
let
chunks
:
Buffer
[]
=
[];
f
.
pass
(
chunks
);
request
.
on
(
'
data
'
,
(
chunk
:
Buffer
)
=>
{
chunks
.
push
(
chunk
);
});
request
.
on
(
'
end
'
,
f
.
wait
());
}
},
(
chunks
)
=>
{
},
(
chunks
:
Buffer
[]
)
=>
{
// If upload was base64, make sure we decode it first.
if
(
contentType
.
includes
(
'
base64
'
))
{
...
...
server/src/lib/db/base-db.ts
View file @
62bd3489
...
...
@@ -9,7 +9,7 @@ export default class BaseDB {
constructor
(
public
mysql
:
Mysql
,
public
name
:
string
,
public
columns
:
Object
,
public
columns
:
any
,
public
index
:
string
)
{}
...
...
@@ -17,9 +17,9 @@ export default class BaseDB {
* Query database, but using promises.
*/
q
(
text
:
string
,
values
?:
any
[])
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
mysql
.
query
(
text
,
null
,(
error
,
results
)
=>
{
return
new
Promise
((
resolve
:
(
rows
:
any
[])
=>
void
,
reject
:
(
error
:
any
)
=>
void
)
=>
{
this
.
mysql
.
query
(
text
,
null
,
(
error
:
any
,
results
:
any
)
=>
{
error
?
reject
(
error
)
:
resolve
(
results
);
});
})
...
...
server/src/lib/db/mysql.ts
View file @
62bd3489
...
...
@@ -67,7 +67,7 @@ export default class Mysql {
}
query
(
text
:
string
,
values
:
any
[],
callback
:
Function
)
{
this
.
pool
.
query
(
text
,
function
(
error
,
results
,
fields
)
{
this
.
pool
.
query
(
text
,
function
(
error
:
any
,
results
:
any
,
fields
:
any
)
{
error
?
callback
(
error
.
message
,
null
)
:
callback
(
null
,
results
);
});
}
...
...
server/src/lib/files.ts
View file @
62bd3489
...
...
@@ -18,13 +18,21 @@ const CONFIG_PATH = path.resolve(__dirname, '../../..',
const
config
=
require
(
CONFIG_PATH
);
const
BUCKET_NAME
=
config
.
BUCKET_NAME
||
'
common-voice-corpus
'
;
interface
FileData
{
sentence
:
string
;
text
:
string
;
sound
:
string
;
votes
:
number
;
pushed
:
boolean
;
}
interface
FileHolder
{
[
key
:
string
]:
FileData
;
}
export
default
class
Files
{
private
s3
:
any
;
private
files
:
{
// fileGlob: [
// sentence: 'the text of the sentenct'
// ]
};
private
files
:
FileHolder
;
private
paths
:
string
[];
private
votes
:
number
;
private
validated
:
number
;
...
...
@@ -53,7 +61,8 @@ export default class Files {
*/
private
fetchSentenceFromS3
(
glob
:
string
):
Promise
<
string
>
{
let
key
=
glob
+
TEXT_EXT
;
return
new
Promise
((
res
,
rej
)
=>
{
return
new
Promise
((
res
:
(
stentence
:
string
)
=>
void
,
rej
:
(
error
:
any
)
=>
void
)
=>
{
let
glob
=
this
.
getGlob
(
key
);
let
params
=
{
Bucket
:
BUCKET_NAME
,
Key
:
key
};
this
.
s3
.
getObject
(
params
,
(
err
:
any
,
s3Data
:
any
)
=>
{
...
...
@@ -117,7 +126,7 @@ export default class Files {
});
let
startRequest
=
Date
.
now
();
awsRequest
.
on
(
'
success
'
,
(
response
)
=>
{
awsRequest
.
on
(
'
success
'
,
(
response
:
any
)
=>
{
let
next
=
response
[
'
data
'
][
'
NextContinuationToken
'
];
let
contents
=
response
[
'
data
'
][
'
Contents
'
];
...
...
@@ -140,7 +149,10 @@ export default class Files {
if
(
!
this
.
files
[
glob
])
{
this
.
files
[
glob
]
=
{
pushed
:
false
,
votes
:
0
sentence
:
null
,
text
:
null
,
sound
:
null
,
votes
:
0
,
};
}
...
...
@@ -181,7 +193,7 @@ export default class Files {
},
LOAD_DELAY
);
});
awsRequest
.
on
(
'
error
'
,
(
response
)
=>
{
awsRequest
.
on
(
'
error
'
,
(
response
:
any
)
=>
{
console
.
error
(
'
Error while fetching clip list
'
,
response
);
// Retry loading current batch.
...
...
@@ -197,7 +209,7 @@ export default class Files {
* Load sound file metadata into memory.
*/
private
loadCache
():
Promise
<
void
>
{
return
new
Promise
((
res
,
rej
)
=>
{
return
new
Promise
((
res
:
Function
,
rej
:
Function
)
=>
{
this
.
loadNext
(
res
,
rej
);
});
}
...
...
server/src/lib/logger.ts
View file @
62bd3489
...
...
@@ -57,11 +57,11 @@ export default class Logger {
}
}
log
(...
args
)
{
log
(...
args
:
any
[]
)
{
this
.
printFields
(
this
.
getMessageFields
(
LEVEL_LOG
,
args
.
join
(
'
,
'
)));
}
error
(...
args
)
{
error
(...
args
:
any
[]
)
{
this
.
printFields
(
this
.
getMessageFields
(
LEVEL_ERROR
,
args
.
join
(
'
,
'
)));
}
...
...
@@ -73,13 +73,13 @@ export default class Logger {
// Override console.log to user our json logger.
this
.
boundLog
=
console
.
log
.
bind
(
console
);
console
.
log
=
(...
args
)
=>
{
console
.
log
=
(...
args
:
any
[]
)
=>
{
this
.
log
(...
args
);
}
// Override console.error to user our json logger.
this
.
boundError
=
console
.
error
.
bind
(
console
);
console
.
error
=
(...
args
)
=>
{
console
.
error
=
(...
args
:
any
[]
)
=>
{
this
.
error
(...
args
);
}
}
...
...
server/src/lib/responder.ts
View file @
62bd3489
...
...
@@ -22,7 +22,7 @@ export default function respond(response: ServerResponse,
content
:
string
=
''
,
statusCode
:
number
=
200
,
contentType
:
string
=
CONTENT_TYPES
.
TXT
,
headers
:
object
=
{},
headers
:
any
=
{},
characterEncoding
:
string
=
'
utf-8
'
)
{
headers
[
'
Content-Type
'
]
=
contentType
;
...
...
server/src/lib/utility.ts
View file @
62bd3489
...
...
@@ -13,7 +13,7 @@ export function getFileExt(path: string): string {
* Returns the first defined argument. Returns null if there are no defined
* arguments.
*/
export
function
getFirstDefined
(...
options
)
{
export
function
getFirstDefined
(...
options
:
any
[]
)
{
for
(
var
i
=
0
;
i
<
options
.
length
;
i
++
)
{
if
(
options
[
i
]
!==
undefined
)
{
return
options
[
i
];
...
...
server/src/server.ts
View file @
62bd3489
...
...
@@ -92,7 +92,7 @@ export default class Server {
}
}
process
.
on
(
'
uncaughtException
'
,
function
(
err
)
{
process
.
on
(
'
uncaughtException
'
,
function
(
err
:
any
)
{
console
.
error
(
'
uncaught exception
'
,
err
);
});
...
...
server/tsconfig.json
View file @
62bd3489
{
"compilerOptions"
:
{
"target"
:
"es5"
,
"noImplicitAny"
:
fals
e
,
"noImplicitAny"
:
tru
e
,
"strictNullChecks"
:
false
,
"noEmitOnError"
:
true
,
"typeRoots"
:
[
"../node_modules/@types"
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment