feat: return logs in csv format
This commit is contained in:
parent
542ba9f1b7
commit
a108df0c4c
7 changed files with 65 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const { gql } = require('apollo-server-express')
|
||||
const converter = require('json-2-csv')
|
||||
const { GraphQLDateTime } = require('graphql-iso-date')
|
||||
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json')
|
||||
const got = require('got')
|
||||
|
|
@ -206,11 +207,14 @@ const typeDefs = gql`
|
|||
customers: [Customer]
|
||||
customer(customerId: ID!): Customer
|
||||
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog]
|
||||
machineLogsCsv(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): String
|
||||
funding: [CoinFunds]
|
||||
serverVersion: String!
|
||||
uptime: [ProcessStatus]
|
||||
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog]
|
||||
serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int): [Transaction]
|
||||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
}
|
||||
|
|
@ -256,12 +260,18 @@ const resolvers = {
|
|||
funding: () => funding.getFunding(),
|
||||
machineLogs: (...[, { deviceId, from, until, limit, offset }]) =>
|
||||
logs.simpleGetMachineLogs(deviceId, from, until, limit, offset),
|
||||
machineLogsCsv: (...[, { deviceId, from, until, limit, offset }]) =>
|
||||
logs.simpleGetMachineLogs(deviceId, from, until, limit, offset).then(converter.json2csvAsync),
|
||||
serverVersion: () => serverVersion,
|
||||
uptime: () => supervisor.getAllProcessInfo(),
|
||||
serverLogs: (...[, { from, until, limit, offset }]) =>
|
||||
serverLogs.getServerLogs(from, until, limit, offset),
|
||||
serverLogsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
serverLogs.getServerLogs(from, until, limit, offset).then(converter.json2csvAsync),
|
||||
transactions: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset),
|
||||
transactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset).then(converter.json2csvAsync),
|
||||
config: () => settingsLoader.loadLatestConfigOrNone(),
|
||||
accounts: () => settingsLoader.loadAccounts()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -185,8 +185,7 @@ const LogsDownloaderPopover = ({ name, query, args, title, getLogs }) => {
|
|||
return moment(date).format('YYYY-MM-DD_HH-mm')
|
||||
}
|
||||
|
||||
const text = logs.map(it => JSON.stringify(it)).join('\n')
|
||||
const blob = new window.Blob([text], {
|
||||
const blob = new window.Blob([logs], {
|
||||
type: 'text/plain;charset=utf-8'
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,17 @@ const GET_MACHINES = gql`
|
|||
|
||||
const NUM_LOG_RESULTS = 500
|
||||
|
||||
const GET_MACHINE_LOGS_CSV = gql`
|
||||
query MachineLogs($deviceId: ID!, $limit: Int, $from: Date, $until: Date) {
|
||||
machineLogsCsv(
|
||||
deviceId: $deviceId
|
||||
limit: $limit
|
||||
from: $from
|
||||
until: $until
|
||||
)
|
||||
}
|
||||
`
|
||||
|
||||
const GET_MACHINE_LOGS = gql`
|
||||
query MachineLogs($deviceId: ID!, $limit: Int, $from: Date, $until: Date) {
|
||||
machineLogs(
|
||||
|
|
@ -87,9 +98,9 @@ const Logs = () => {
|
|||
<LogsDowloaderPopover
|
||||
title="Download logs"
|
||||
name="machine-logs"
|
||||
query={GET_MACHINE_LOGS}
|
||||
query={GET_MACHINE_LOGS_CSV}
|
||||
args={{ deviceId }}
|
||||
getLogs={logs => R.path(['machineLogs'])(logs)}
|
||||
getLogs={logs => R.path(['machineLogsCsv'])(logs)}
|
||||
/>
|
||||
<Info3>{saveMessage}</Info3>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@ const formatDate = date => {
|
|||
|
||||
const NUM_LOG_RESULTS = 500
|
||||
|
||||
const GET_CSV = gql`
|
||||
query ServerData($limit: Int, $from: Date, $until: Date) {
|
||||
serverLogsCsv(limit: $limit, from: $from, until: $until)
|
||||
}
|
||||
`
|
||||
|
||||
const GET_DATA = gql`
|
||||
query ServerData($limit: Int, $from: Date, $until: Date) {
|
||||
serverVersion
|
||||
|
|
@ -118,9 +124,9 @@ const Logs = () => {
|
|||
<LogsDowloaderPopover
|
||||
title="Download logs"
|
||||
name="server-logs"
|
||||
query={GET_DATA}
|
||||
query={GET_CSV}
|
||||
logs={data.serverLogs}
|
||||
getLogs={logs => R.path(['serverLogs'])(logs)}
|
||||
getLogs={logs => R.path(['serverLogsCsv'])(logs)}
|
||||
/>
|
||||
<Info3>{saveMessage}</Info3>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ const useStyles = makeStyles(mainStyles)
|
|||
|
||||
const NUM_LOG_RESULTS = 1000
|
||||
|
||||
const GET_TRANSACTIONS_CSV = gql`
|
||||
query transactions($limit: Int, $from: Date, $until: Date) {
|
||||
transactionsCsv(limit: $limit, from: $from, until: $until)
|
||||
}
|
||||
`
|
||||
|
||||
const GET_TRANSACTIONS = gql`
|
||||
query transactions($limit: Int, $from: Date, $until: Date) {
|
||||
transactions(limit: $limit, from: $from, until: $until) {
|
||||
|
|
@ -142,8 +148,8 @@ const Transactions = () => {
|
|||
<LogsDowloaderPopover
|
||||
title="Download logs"
|
||||
name="transactions"
|
||||
query={GET_TRANSACTIONS}
|
||||
getLogs={logs => R.path(['transactions'])(logs)}
|
||||
query={GET_TRANSACTIONS_CSV}
|
||||
getLogs={logs => R.path(['transactionsCsv'])(logs)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
29
package-lock.json
generated
29
package-lock.json
generated
|
|
@ -3265,6 +3265,11 @@
|
|||
"mimic-response": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"deeks": {
|
||||
"version": "2.2.7",
|
||||
"resolved": "https://registry.npmjs.org/deeks/-/deeks-2.2.7.tgz",
|
||||
"integrity": "sha512-pCKFxSqyY2LAQ3qKQ+y+wOG63Bb9uDmDiHUVnrTR10AP75BVo2QMlgm36G+oPpRDPrgAiw5p9d+lAxdsqOwOyA=="
|
||||
},
|
||||
"deep-extend": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
||||
|
|
@ -3434,6 +3439,11 @@
|
|||
"path-type": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"doc-path": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/doc-path/-/doc-path-2.1.2.tgz",
|
||||
"integrity": "sha512-saM17czrIb4jYLsS5728OKbCa/WQ3xVctkGiMixOHz3X1VYsRn/Q5xPMxE1A5WN+XHHLWak34mMMjmAKRgMLeA=="
|
||||
},
|
||||
"doctrine": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
|
||||
|
|
@ -4985,7 +4995,7 @@
|
|||
"got": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-7.1.0.tgz",
|
||||
"integrity": "sha1-BUUP2ECU5rvqVvRRpDqcKJFmOFo=",
|
||||
"integrity": "sha512-Y5WMo7xKKq1muPsxD+KmrR8DH5auG7fBdDVueZwETwV6VytKyU9OX/ddpq2/1hp1vIPvVb4T81dKQz3BivkNLw==",
|
||||
"requires": {
|
||||
"decompress-response": "^3.2.0",
|
||||
"duplexer3": "^0.1.4",
|
||||
|
|
@ -5801,7 +5811,7 @@
|
|||
"isurl": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isurl/-/isurl-1.0.0.tgz",
|
||||
"integrity": "sha1-sn9PSfPNqj6kSgpbfzRi5u3DnWc=",
|
||||
"integrity": "sha512-1P/yWsxPlDtn7QeRD+ULKQPaIaN6yF368GZ2vDfv0AL0NwpStafjWCDDdn0k8wgFMWpVAqG7oJhxHnlud42i9w==",
|
||||
"requires": {
|
||||
"has-to-string-tag-x": "^1.2.0",
|
||||
"is-object": "^1.0.1"
|
||||
|
|
@ -5870,6 +5880,15 @@
|
|||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM="
|
||||
},
|
||||
"json-2-csv": {
|
||||
"version": "3.7.8",
|
||||
"resolved": "https://registry.npmjs.org/json-2-csv/-/json-2-csv-3.7.8.tgz",
|
||||
"integrity": "sha512-2CDoU32s/RA9a9xPRVsLDgk7UMW5u2SzrdklsNDl8tmdHUWT7JN2+eUV1hn1TuxJyrJxQjEXM5K4kTTnpY5+Pw==",
|
||||
"requires": {
|
||||
"deeks": "2.2.7",
|
||||
"doc-path": "2.1.2"
|
||||
}
|
||||
},
|
||||
"json-buffer": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
|
||||
|
|
@ -6571,7 +6590,7 @@
|
|||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
|
|
@ -6915,7 +6934,7 @@
|
|||
"npmlog": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
|
||||
"integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=",
|
||||
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
|
||||
"requires": {
|
||||
"are-we-there-yet": "~1.1.2",
|
||||
"console-control-strings": "~1.1.0",
|
||||
|
|
@ -7216,7 +7235,7 @@
|
|||
"p-cancelable": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz",
|
||||
"integrity": "sha1-ueEjgAvOu3rBOkeb4ZW1B7mNMPo="
|
||||
"integrity": "sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw=="
|
||||
},
|
||||
"p-defer": {
|
||||
"version": "1.0.0",
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
"graphql-type-json": "^0.3.1",
|
||||
"helmet": "^3.8.1",
|
||||
"inquirer": "^5.2.0",
|
||||
"json-2-csv": "^3.7.8",
|
||||
"kraken-api": "github:DeX3/npm-kraken-api",
|
||||
"libphonenumber-js": "^1.7.38",
|
||||
"lnd-async": "^1.8.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue