update image path & add user

This commit is contained in:
pakintada@gmail.com 2024-01-24 11:58:39 +07:00
parent dd532e7e7d
commit bdd3762cd1
6 changed files with 84 additions and 3 deletions

View file

@ -42,6 +42,7 @@ export class MaterialService {
): Promise<Observable<{
"materialId": number,
"name": string,
"nameEN": string,
"type": string
}[] | null>>{
console.log("getFullMaterialDetail", country, "where filename = ",filename, "department.short = ", this.department!);
@ -59,6 +60,7 @@ export class MaterialService {
return this._httpClient.get<{
"materialId": number,
"name": string,
"nameEN": string,
"type": string
}[]>(`${environment.api}/materials/full/${country}/${filename}`, {
withCredentials: true,

View file

@ -42,7 +42,9 @@
<div class="flex p-3 items-center justify-center w-full">
<img
class="rounded-lg shadow"
src="/assets/{{ 'bn_hot_america_no' }}.png"
src="{{imagePath(this.productCode)}}"
alt="/assets/{{ 'bn_hot_america_no' }}.png"
onerror="this.onerror=null;this.src='/assets/bn_hot_america_no.png'"
/>
</div>
</div>
@ -110,10 +112,12 @@
<input class="input input-sm input-bordered input-ghost w-full text-center" type="text" name="price" value="{{recipePrice()}}">
</div>
<div *ngIf="hasSubmenu()">
<div class="flex flex-col p-4 items-center m-4 bg-stone-200 rounded-md w-1/2 space-y-2 tooltip" *ngIf="hasSubmenu()" data-tip="Menus related to this recipe">
<p class="text-md font-semibold">Related Menu</p>
<div *ngFor="let sub of listSubMenuProductcodes()">
<a
class="btn btn-sm btn-primary m-2"
class="bg-slate-300 p-2 rounded-md text-md font-medium"
href="/{{department}}/recipe/{{ sub }}"
>
{{ sub }}

View file

@ -21,6 +21,7 @@ import { ToppingService } from 'src/app/core/services/topping.service';
import { copy, transformToTSV } from 'src/app/shared/helpers/copy';
import { isEqual } from 'lodash';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-recipe-details',
@ -346,4 +347,18 @@ export class RecipeDetailsComponent implements OnInit {
Object.keys(this.rawRecipe as any).includes('cashPrice')
? (this.rawRecipe as any).cashPrice
: 0;
// image path
imagePath = (productCode: string) => {
const filename = this._recipeService.getCurrentFile();
return environment.api +
'/recipes/' +
this.department +
'/' +
filename +
'/' +
productCode +
'/image';
};
}

1
server/.gitignore vendored
View file

@ -1,4 +1,5 @@
**/cofffeemachineConfig/*
**/taobin_project/*
**/*.log
token.json
client_secret.json

View file

@ -3,6 +3,7 @@ package routers
import (
"encoding/json"
"fmt"
"image/png"
"net/http"
"os"
"path"
@ -64,6 +65,9 @@ func (rr *RecipeRouter) Route(r chi.Router) {
// fetch raw recipe json
r.Get("/{country}/{filename}/{product_code}/raw_full", rr.getRawRecipeOfProductCode)
// fetch image
r.Get("/{country}/{filename}/{product_code}/image", rr.getImageOfProductCode)
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
@ -574,6 +578,60 @@ func (rr *RecipeRouter) getRawRecipeOfProductCode(w http.ResponseWriter, r *http
json.NewEncoder(w).Encode(recipe)
}
func (rr *RecipeRouter) getImageOfProductCode(w http.ResponseWriter, r *http.Request) {
countryID := chi.URLParam(r, "country")
filename := chi.URLParam(r, "filename")
productCode := chi.URLParam(r, "product_code")
w.Header().Add("Content-Type", "image/png")
// get image
recipe, err := rr.data.GetRecipe01ByProductCode(filename, countryID, productCode)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
// check if image string is not empty
if recipe.UriData == "" {
http.Error(w, "Image not found", http.StatusNotFound)
return
}
// clean image uri name
clean1 := strings.Replace(recipe.UriData, "\u003d", "=", -1)
uriName := strings.Split(clean1, "=")[1]
img_dir := "taobin_project/image/page_drink_picture2_n/"
fullPath := img_dir + uriName
rr.taoLogger.Log.Debug("RecipeRouter.getImageOfProductCode", zap.Any("fullPath", fullPath))
// check if image file exists
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
http.Error(w, "Image not found", http.StatusNotFound)
return
}
// read image
imgFile, err := os.Open(fullPath)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
defer imgFile.Close()
thisImage, err := png.Decode(imgFile)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
// write image
png.Encode(w, thisImage)
}
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
// TODO: v2, change to binary instead
if !APIhandler(w, r) {

View file

@ -116,6 +116,7 @@ func (s *Server) createHandler() {
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.SuperAdmin)
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "phu", "pakin.t@forth.co.th", "", permissions.SuperAdmin)
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "wanlop", "wanlop.r@forth.co.th", "", permissions.SuperAdmin)
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "dawit", "dawit.o@forth.co.th", "", permissions.SuperAdmin)
// Auth Router
r.Group(func(r chi.Router) {