1
1
import { Injectable } from '@nestjs/common' ;
2
2
import { APIService } from 'src/apis/apis.service' ;
3
- import { ObjectStructureInfo , ParserService } from 'src/json_parser/parser.service' ;
3
+ import { colors } from 'src/config' ;
4
+ import { ObjectStructureInfo } from 'src/json_parser/parser.service' ;
4
5
5
6
6
7
@Injectable ( )
7
8
export class WidgetService {
8
- constructor ( private readonly parserService : ParserService ,
9
+ constructor (
9
10
private readonly apiService : APIService ,
10
11
) { }
11
12
@@ -66,7 +67,7 @@ export class WidgetService {
66
67
return acc ;
67
68
} , { } ) ;
68
69
69
- const top_langs = wakatime_last . data ?. slice ( 0 , 3 ) ?. reduce ( ( acc , value ) => {
70
+ const top_langs = wakatime_last ? .data ?. slice ( 0 , 3 ) ?. reduce ( ( acc , value ) => {
70
71
const el = { [ value . name . toLowerCase ( ) . replaceAll ( '+' , 'p' ) ] : value . text } ;
71
72
acc = { ...acc , ...el } ;
72
73
return acc ;
@@ -75,21 +76,21 @@ export class WidgetService {
75
76
json = {
76
77
name : github_data . data . user ?. name ?? 'n/a' ,
77
78
description : process . env . DESCRIPTION ,
78
- followers : github_data . data . user ?. followers ?. totalCount ?? 'n/a' ,
79
- total_stars : github_data . data . user ?. repositories ?. totalCount ?? 'n/a' ,
80
- top_repos : top_repos ?? 'n/a' ,
79
+ followers : github_data . data . user ?. followers ?. totalCount ,
80
+ total_stars : github_data . data . user ?. repositories ?. totalCount ,
81
+ top_repos : top_repos ,
81
82
github_streak : streak ? {
82
83
current_streak : streak . streak ,
83
84
longest_streak : streak . longest
84
- } : 'n/a' ,
85
+ } : undefined ,
85
86
wakatime : {
86
- all_time : wakatime_global . data . grand_total . human_readable_total_including_other_language ?? 'n/a' ,
87
- top_langs : top_langs ?? 'n/a'
87
+ all_time : wakatime_global ? .data ? .grand_total ? .human_readable_total_including_other_language ,
88
+ top_langs : top_langs
88
89
} ,
89
90
weather : weather ? {
90
91
temperature : weather . temp ,
91
92
condition : weather . condition
92
- } : 'n/a' ,
93
+ } : undefined ,
93
94
datetime : {
94
95
time : this . getTime ( ) ,
95
96
tz : process . env . DATETIME_TIMEZONE ,
@@ -109,22 +110,13 @@ export class WidgetService {
109
110
message : ( e . message ?? "Unknown error. See server console." ) . slice ( 0 , 60 ) + ( ! ! e . message && e . message . length > 60 ? '...' : '' )
110
111
}
111
112
}
112
-
113
- const indents = this . parserService . analyzeObjectStructureFlat ( json ) ;
114
- return {
115
- main : this . parserService . parse ( json , 30 ) ,
116
- indents : this . generateIndentLines ( indents , 30 )
117
- } ;
118
- }
119
-
120
- async generateUser ( obj : any ) {
121
- return this . parserService . parse ( obj , 30 ) ;
113
+ return json ;
122
114
}
123
115
124
116
generate_indexes ( count : number ) {
125
117
const array = [ ] ;
126
118
for ( let index = 1 ; index <= count ; index ++ ) {
127
- array . push ( `<tspan x="${ index < 10 ? '9' : '0' } " dy="${ index === 1 ? '0' : '19' } ">${ index } </tspan>` ) ;
119
+ array . push ( `<tspan x="${ index < 10 ? '9' : '0' } " dy="${ index === 1 ? '0' : '19' } " fill=" ${ colors . line_index } " >${ index } </tspan>` ) ;
128
120
}
129
121
130
122
return array . join ( '\n' ) ;
@@ -134,7 +126,7 @@ export class WidgetService {
134
126
const array = [ ] ;
135
127
for ( const indent of indents ) {
136
128
array . push (
137
- `<rect fill="#404040 " x="${ indent . depth * indent_width } " ` +
129
+ `<rect fill="${ colors . indent_lines } " x="${ indent . depth * indent_width } " ` +
138
130
`y="${ indent . startLine * 19 } " width="1" height="${ ( ( indent . endLine - indent . startLine ) - 1 ) * 19 } " />`
139
131
) ;
140
132
}
0 commit comments