mirror of
https://github.com/seejohnrun/haste-server.git
synced 2026-02-06 08:01:32 +00:00
add prettier
This commit is contained in:
@@ -22,7 +22,7 @@ class AmazonS3DocumentStore implements Store {
|
||||
get = (
|
||||
key: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
if (!this.bucket) {
|
||||
callback(false)
|
||||
@@ -31,7 +31,7 @@ class AmazonS3DocumentStore implements Store {
|
||||
|
||||
const req = {
|
||||
Bucket: this.bucket,
|
||||
Key: key,
|
||||
Key: key
|
||||
}
|
||||
|
||||
this.client.getObject(req, (err, data) => {
|
||||
@@ -50,7 +50,7 @@ class AmazonS3DocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
if (!this.bucket) {
|
||||
callback(false)
|
||||
@@ -61,7 +61,7 @@ class AmazonS3DocumentStore implements Store {
|
||||
Bucket: this.bucket,
|
||||
Key: key,
|
||||
Body: data as AWS.S3.PutObjectOutput,
|
||||
ContentType: 'text/plain',
|
||||
ContentType: 'text/plain'
|
||||
}
|
||||
|
||||
this.client.putObject(req, err => {
|
||||
|
||||
@@ -33,7 +33,7 @@ class FileDocumentStore implements Store {
|
||||
get = (
|
||||
key: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
const fn = `${this.basePath}/${md5(key)}`
|
||||
fs.readFile(fn, 'utf8', (err, data) => {
|
||||
@@ -54,7 +54,7 @@ class FileDocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
try {
|
||||
fs.mkdir(this.basePath, '700', () => {
|
||||
|
||||
@@ -26,7 +26,7 @@ class GoogleDatastoreDocumentStore implements Store {
|
||||
key: PathType,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean,
|
||||
skipExpire?: boolean
|
||||
) => {
|
||||
const expireTime =
|
||||
skipExpire || this.expire === undefined
|
||||
@@ -40,13 +40,13 @@ class GoogleDatastoreDocumentStore implements Store {
|
||||
{
|
||||
name: 'value',
|
||||
value: data,
|
||||
excludeFromIndexes: true,
|
||||
excludeFromIndexes: true
|
||||
},
|
||||
{
|
||||
name: 'expiration',
|
||||
value: expireTime,
|
||||
},
|
||||
],
|
||||
value: expireTime
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.datastore
|
||||
@@ -72,7 +72,7 @@ class GoogleDatastoreDocumentStore implements Store {
|
||||
winston.info('document expired', {
|
||||
key,
|
||||
expiration: entity[0].expiration,
|
||||
check: new Date(),
|
||||
check: new Date()
|
||||
})
|
||||
callback(false)
|
||||
} else {
|
||||
@@ -83,15 +83,15 @@ class GoogleDatastoreDocumentStore implements Store {
|
||||
{
|
||||
name: 'value',
|
||||
value: entity[0].value,
|
||||
excludeFromIndexes: true,
|
||||
excludeFromIndexes: true
|
||||
},
|
||||
{
|
||||
name: 'expiration',
|
||||
value: new Date(
|
||||
Date.now() + (this.expire ? this.expire * 1000 : 0),
|
||||
),
|
||||
},
|
||||
],
|
||||
Date.now() + (this.expire ? this.expire * 1000 : 0)
|
||||
)
|
||||
}
|
||||
]
|
||||
}
|
||||
this.datastore
|
||||
.update(task)
|
||||
@@ -104,7 +104,7 @@ class GoogleDatastoreDocumentStore implements Store {
|
||||
})
|
||||
.catch(err => {
|
||||
winston.error('Error retrieving value from Google Datastore', {
|
||||
error: err,
|
||||
error: err
|
||||
})
|
||||
callback(false)
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ class MemcachedDocumentStore implements Store {
|
||||
get = (
|
||||
key: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
this.client?.get(key, (error, data: string) => {
|
||||
const value = error ? false : data
|
||||
@@ -53,7 +53,7 @@ class MemcachedDocumentStore implements Store {
|
||||
winston.error('failed to update expiration on GET', { key })
|
||||
}
|
||||
},
|
||||
skipExpire,
|
||||
skipExpire
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -64,7 +64,7 @@ class MemcachedDocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
this.client?.set(key, data, skipExpire ? 0 : this.expire || 0, error => {
|
||||
callback(!error)
|
||||
|
||||
@@ -33,7 +33,7 @@ class MongoDocumentStore implements Store {
|
||||
get = (
|
||||
key: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
const now = Math.floor(new Date().getTime() / 1000)
|
||||
|
||||
@@ -46,7 +46,7 @@ class MongoDocumentStore implements Store {
|
||||
.findOne(
|
||||
{
|
||||
entry_id: key,
|
||||
$or: [{ expiration: -1 }, { expiration: { $gt: now } }],
|
||||
$or: [{ expiration: -1 }, { expiration: { $gt: now } }]
|
||||
},
|
||||
(error?: Error, entry?) => {
|
||||
if (error) {
|
||||
@@ -67,20 +67,20 @@ class MongoDocumentStore implements Store {
|
||||
.collection('entries')
|
||||
.update(
|
||||
{
|
||||
entry_id: key,
|
||||
entry_id: key
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
expiration: this.expire + now,
|
||||
},
|
||||
expiration: this.expire + now
|
||||
}
|
||||
},
|
||||
{},
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class MongoDocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
const now = Math.floor(new Date().getTime() / 1000)
|
||||
|
||||
@@ -102,15 +102,15 @@ class MongoDocumentStore implements Store {
|
||||
.update(
|
||||
{
|
||||
entry_id: key,
|
||||
$or: [{ expiration: -1 }, { expiration: { $gt: now } }],
|
||||
$or: [{ expiration: -1 }, { expiration: { $gt: now } }]
|
||||
},
|
||||
{
|
||||
entry_id: key,
|
||||
value: data,
|
||||
expiration: this.expire && !skipExpire ? this.expire + now : -1,
|
||||
expiration: this.expire && !skipExpire ? this.expire + now : -1
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
upsert: true
|
||||
},
|
||||
(error?: Error) => {
|
||||
if (error) {
|
||||
@@ -119,7 +119,7 @@ class MongoDocumentStore implements Store {
|
||||
}
|
||||
|
||||
return callback(true)
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { PostgresStoreConfig } from 'src/types/config'
|
||||
type ConnectCallback = (
|
||||
error?: Error,
|
||||
client?: PoolClient,
|
||||
done?: () => void,
|
||||
done?: () => void
|
||||
) => void
|
||||
|
||||
// A postgres document store
|
||||
@@ -42,7 +42,7 @@ class PostgresDocumentStore implements Store {
|
||||
get = (
|
||||
key: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
const now = Math.floor(new Date().getTime() / 1000)
|
||||
this.safeConnect((err, client, done): void => {
|
||||
@@ -56,7 +56,7 @@ class PostgresDocumentStore implements Store {
|
||||
(error: Error, result) => {
|
||||
if (error) {
|
||||
winston.error('error retrieving value from postgres', {
|
||||
error,
|
||||
error
|
||||
})
|
||||
return callback(false)
|
||||
}
|
||||
@@ -71,12 +71,12 @@ class PostgresDocumentStore implements Store {
|
||||
}
|
||||
|
||||
return callback(false)
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return done?.()
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class PostgresDocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
const now = Math.floor(new Date().getTime() / 1000)
|
||||
this.safeConnect((err, client, done) => {
|
||||
@@ -103,7 +103,7 @@ class PostgresDocumentStore implements Store {
|
||||
}
|
||||
callback(true)
|
||||
return done?.()
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,18 +35,20 @@ class RedisDocumentStore implements Store {
|
||||
const port = options.port || 6379
|
||||
const index = options.db || 0
|
||||
|
||||
const connectionParameters = url ? {
|
||||
url
|
||||
}: {
|
||||
host,
|
||||
port
|
||||
}
|
||||
const connectionParameters = url
|
||||
? {
|
||||
url
|
||||
}
|
||||
: {
|
||||
host,
|
||||
port
|
||||
}
|
||||
|
||||
const config = {
|
||||
...connectionParameters,
|
||||
database: index as number,
|
||||
...(options.username ? { username: options.username } : {}),
|
||||
...(options.password ? { username: options.username } : {}),
|
||||
...(options.password ? { username: options.username } : {})
|
||||
}
|
||||
|
||||
this.client = createClient(config)
|
||||
@@ -63,7 +65,7 @@ class RedisDocumentStore implements Store {
|
||||
})
|
||||
.catch(err => {
|
||||
winston.error(`error connecting to redis index ${index}`, {
|
||||
error: err,
|
||||
error: err
|
||||
})
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -86,7 +88,7 @@ class RedisDocumentStore implements Store {
|
||||
key: string,
|
||||
data: string,
|
||||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
skipExpire?: boolean | undefined
|
||||
): void => {
|
||||
this.client
|
||||
?.set(key, data, this.getExpire(skipExpire))
|
||||
|
||||
@@ -22,7 +22,7 @@ class RethinkDBStore {
|
||||
port: options.port || 28015,
|
||||
db: options.db || 'haste',
|
||||
user: options.user || 'admin',
|
||||
password: options.password || '',
|
||||
password: options.password || ''
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user