1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Add documentation for aliases.

Reload aliases for every summary request.
This commit is contained in:
Ferdinand Mütsch 2019-07-07 10:32:28 +02:00
parent e98acb8315
commit e18a873428
4 changed files with 23 additions and 11 deletions

View File

@ -30,6 +30,22 @@
* Select your database: `USE yourdatabasename;`
* Add the new user: `INSERT INTO users (id, password, api_key) VALUES ('your_nickname', MD5('your_password'), '728f084c-85e0-41de-aa2a-b6cc871200c1');` (the latter value should be a random [UUIDv4](https://tools.ietf.org/html/rfc4122), as can be found in your `~/.wakatime.cfg`)
### Aliases
There is an option to add aliases for project names, editors, operating systems and languages. For instance, if you want to map two projects `myapp-frontend` and `myapp-backend` two a common project name `myapp-web` in your statistics, you can add project aliases.
At the moment, this can only be done via raw database queries. See [_User Accounts_](#user-accounts) section above on how to do such.
For the above example, you would need to add two aliases, like this:
* `INSERT INTO aliases (type, user_id, key, value) VALUES (0, 'your_username', 'myapp-web', 'myapp-frontend')` (analogously for `myapp-backend`)
#### Types
* Project ~ type **0**
* Language ~ type **1**
* Editor ~ type **2**
* OS ~ type **3**
**NOTE:** In order for the aliases to take effect for non-live statistics, you would either have to wait 24 hours for the cache to be invalidated or restart Wakapi.
## Best Practices
It is recommended to use wakapi behind a **reverse proxy**, like [Caddy](https://caddyserver.com) or _nginx_ to enable **TLS encryption** (HTTPS).
However, if you want to expose your wakapi instance to the public anyway, you need to set `listen = 0.0.0.0` in `config.ini`

View File

@ -2,7 +2,6 @@ package routes
import (
"crypto/md5"
"log"
"net/http"
"strconv"
"time"
@ -14,7 +13,7 @@ import (
)
const (
IntervalToday string = "today"
IntervalToday string = "today"
IntervalLastDay string = "day"
IntervalLastWeek string = "week"
IntervalLastMonth string = "month"
@ -45,15 +44,8 @@ func (h *SummaryHandler) Get(w http.ResponseWriter, r *http.Request) {
}
user := r.Context().Value(models.UserKey).(*models.User)
// Initialize aliases for user
if !h.SummarySrvc.AliasService.IsInitialized(user.ID) {
log.Printf("Initializing aliases for user '%s'\n", user.ID)
h.SummarySrvc.AliasService.InitUser(user.ID)
}
params := r.URL.Query()
interval := params.Get("interval")
interval := params.Get("interval")
from, err := utils.ParseDate(params.Get("from"))
if err != nil {
switch interval {

View File

@ -14,7 +14,7 @@ type AliasService struct {
var userAliases map[string][]*models.Alias
func (srv *AliasService) InitUser(userId string) error {
func (srv *AliasService) LoadUserAliases(userId string) error {
if userAliases == nil {
userAliases = make(map[string][]*models.Alias)
}

View File

@ -28,6 +28,10 @@ func (srv *SummaryService) GetSummary(from, to time.Time, user *models.User) (*m
var editorItems []models.SummaryItem
var osItems []models.SummaryItem
if err := srv.AliasService.LoadUserAliases(user.ID); err != nil {
return nil, err
}
c := make(chan models.SummaryItemContainer)
for _, t := range types {
go srv.aggregateBy(heartbeats, t, user, c)