Skip to content

Commit

Permalink
Merge pull request #40 from tomoish/cashe
Browse files Browse the repository at this point in the history
キャッシュを追加し、持続時間を1時間に
  • Loading branch information
kou7306 authored Feb 2, 2024
2 parents 54d4387 + abe8a1c commit 0b599eb
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 22 deletions.
Binary file removed src/NotoSansJP-Black.ttf
Binary file not shown.
Binary file removed src/NotoSansJP-ExtraLight.ttf
Binary file not shown.
24 changes: 21 additions & 3 deletions src/funcs/create_language_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,27 @@ import (
func CreateLanguageImg(username string) []LanguageStat {
// 言語ごとの色をここで決める
colordict := map[string]string{
"HTML": "#E34F26",
"CSS": "#ffffff",
"Python": "#3498DB",
"HTML": "#ff0000",

Check failure on line 13 in src/funcs/create_language_img.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"CSS": "#ffa500",
"Python": "#000080",
"JavaScript": "#ffff00",
"TypeScript": "#3cb371",
"R": "#9932cc",
"Go": "#87cefa",
"Scala": "##006400",
"Flutter" :"#4169e1",
"Rust": "#696969",
"assembly": "#ffd700",
"C": "#f0e68c",
"C++": "#ff69b4",
"Objective-C": "#a52a2a",
"Matlab": "#ff6347",
"C#": "#800080",
"Swift": "#800000",
"Kotlin": "#bdb76b",
"Ruby": "#ee82ee",
"PHP": "#808000",
"Java": "#daa520",
"others": "#000000",
}

Expand Down
2 changes: 1 addition & 1 deletion src/funcs/draw_background.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func DrawBackground(username, level, kind string) {
x2, y2 := (13*Width)/100, (25*Height)/100 // テキスト2の座標(テキストの中央に持つ)
dc.DrawStringAnchored(text2, float64(x2), float64(y2), 0.5, 0.5)

if err := dc.LoadFontFace("NotoSansJP-ExtraLight.ttf", 30); err != nil {
if err := dc.LoadFontFace("ipaexg.ttf", 30); err != nil {
fmt.Println("フォントのロードに失敗しました:", err)
}
text3 := kind
Expand Down
3 changes: 1 addition & 2 deletions src/funcs/draw_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type LanguageStat struct {
func drawRoundedRectangle(dc *gg.Context, x, y, w, h, r float64) {
dc.DrawRectangle(x, y, w, h)
dc.Fill()

}

func GenerateLanguageUsageGraph(languages []LanguageStat, width, height int) ([]byte, error) {
Expand All @@ -37,7 +36,7 @@ func GenerateLanguageUsageGraph(languages []LanguageStat, width, height int) ([]

// 帯グラフの基準点
barX := 40.0
barY := 100.0
barY := 120.0
barHeight := 10.0
barWidth := float64(width) - 80.0

Expand Down
4 changes: 2 additions & 2 deletions src/funcs/merge_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func loadImage(filename string) (image.Image, error) {
//原点(0, 0)は背景画像の左上隅

// すべての画像のパスを受け取り、それらを合成した画像を生成する関数
func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg string) {
func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg ,filepath string) {

Check failure on line 34 in src/funcs/merge_all.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
// 背景画像を黒で生成
// backgroundWidth := 2000 // 背景画像の幅
// backgroundHeight := 1900 // 背景画像の高さ
Expand Down Expand Up @@ -110,7 +110,7 @@ func Merge_all(nameImg, statsImg, characterImg, languageImg, dateImg string) {
}

// 合成した画像を保存
saveImage(backgroundImage, "result.png")
saveImage(backgroundImage, filepath)
ResizeImage("result.png", 700, 0)
}

Expand Down
Binary file modified src/images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/commits_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/gauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/generate_character.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/language.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ipaexg.ttf
Binary file not shown.
45 changes: 31 additions & 14 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"fmt"
"github.com/tomoish/readme/funcs"
"github.com/tomoish/readme/graphs"
"log"
"net/http"
"strconv"

"github.com/tomoish/readme/funcs"
"github.com/tomoish/readme/graphs"
"os"
)

// func handler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -115,12 +115,22 @@ func getHistoryHandler(w http.ResponseWriter, r *http.Request) {
// }

// 画像生成エンドポイント
func createHandler(w http.ResponseWriter, r *http.Request) {

func createhandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "public, max-age=3600")

queryValues := r.URL.Query()
username := queryValues.Get("username")
if r.Method == http.MethodGet {
// GETリクエストの処理
// 一意の画像ファイル名の生成(例: ユーザー名とタイムスタンプを組み合わせる)
imageFileName := fmt.Sprintf("result_%s.png", username)

// 画像ファイルの存在チェック
if _, err := os.Stat(imageFileName); os.IsNotExist(err) {
// 画像が存在しない場合は、新たに生成

// 画像生成の処理...
// stats取得と画像生成
stats := funcs.CreateUserStats(username)
total := stats.TotalStars + stats.ContributedTo + stats.TotalIssues + stats.TotalPRs + stats.TotalCommits
Expand Down Expand Up @@ -148,17 +158,17 @@ func createHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
}

// 全て合体
funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png")
// 全て合体して画像を保存
funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png", imageFileName)
}

// キャッシュ制御ヘッダーを設定
w.Header().Set("Cache-Control", "public, max-age=3600")

// 生成済みの画像ファイルをクライアントに返す
http.ServeFile(w, r, imageFileName)


http.ServeFile(w, r, "./result.png")
// } else if r.Method == http.MethodPost {
// // POSTリクエストの処理
// totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := funcs.FetchData(username)
// if err != nil {
// fmt.Println(err)
// return
// }

} else {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
Expand Down Expand Up @@ -204,3 +214,10 @@ func main() {
// fmt.Println("totalRepositoryContributions: ", totalRepositoryContributions)
fmt.Println(funcs.JudgeProfession("C+", []string{"Go"}, []float64{100}))
}
// } else if r.Method == http.MethodPost {
// // POSTリクエストの処理
// totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := funcs.FetchData(username)
// if err != nil {
// fmt.Println(err)
// return
// }
Binary file modified src/result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/result_kou7306.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0b599eb

Please sign in to comment.