step 8 : configurasi url path selfie, load file, image not found, and deploy to devone

This commit is contained in:
sindhu
2024-01-23 14:54:36 +07:00
parent d3fe3234eb
commit f83fe2dab0
8 changed files with 80 additions and 13 deletions

View File

@@ -3,4 +3,13 @@ dbuser: absensiUser
dbpass: absensi102938
dbhost: devone.aplikasi.web.id
dbport: 3306
dbname: absensi
dbname: absensi
# lokasi file
clockInFolder: ./selfie_attachment/
clockOutFolder: ./selfie_attachment/
cutiFolder: ./cuti/
ijinFolder: ./ijin/
# lokasi file not found
notFoundImage: ./no_image_found.jpg

View File

@@ -147,11 +147,12 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
var varGetM_StaffNIP string
var varProsesFotoSelfie string
var jamClockIn string
var varFileName string
// check user token
qCheckTokenStaff := `SELECT
M_StaffToken,
M_StaffNIP
LOWER(M_StaffNIP) AS M_StaffNIP
FROM m_staff
WHERE M_StaffIsActive = 'Y'
AND M_StaffToken = ?
@@ -232,15 +233,6 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
log.Printf("documentPath: %s", photoPath)
// create folder selfie_attachment jika belum ada
// if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
// err = os.MkdirAll(photoPath, os.ModePerm)
// if err != nil {
// log.Printf("here %v", err)
// return &ret, err
// }
// }
if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
err = os.MkdirAll(photoPath, os.ModePerm.Perm())
if err != nil {
@@ -268,7 +260,8 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
fs.Write(decodedByte)
fs.Sync()
varProsesFotoSelfie = strPhoto
varProsesFotoSelfie = "selfie_attachment/" + folderName + "/" + strPhoto
varFileName = strPhoto
}
qInsertClockIn := `INSERT INTO t_transaction (
@@ -280,7 +273,8 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
T_TransactionCurrentLatitude,
T_TransactionCurrentLongitude,
T_TransactionCurrentDistance,
T_TransactionSelfiePhoto,
T_TransactionFileName,
T_TransactionSelfiePhotoPath,
T_TransactionIsActive,
T_TransactionCreated
) VALUES (
@@ -294,6 +288,7 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
?,
?,
?,
?,
NOW()
)`
@@ -305,6 +300,7 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
T_TransactionCurrentLatitude,
T_TransactionCurrentLongitude,
T_TransactionCurrentDistance,
&varFileName,
&varProsesFotoSelfie,
"Y",
)

BIN
backend/no_image_found.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 KiB

BIN
backend/server Normal file

Binary file not shown.

View File

@@ -42,6 +42,68 @@ func main() {
srv := handler.NewDefaultServer(
generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{}}))
// get file selfie
router.Get("/img/{typeAbsensi}/{subfolder}/{imgname}", func(w http.ResponseWriter, r *http.Request) {
// inisialisasi
var urlPath string
// get from url param
typeAbsensi := chi.URLParam(r, "typeAbsensi")
subfolder := chi.URLParam(r, "subfolder")
imgname := chi.URLParam(r, "imgname")
// check param empty
if typeAbsensi == "" {
w.Write([]byte("Invalid typeAbsensi"))
return
}
if subfolder == "" {
w.Write([]byte("Invalid subfolder"))
return
}
if imgname == "" {
// w.Write([]byte("Invalid imgname"))
http.ServeFile(w, r, config.Data.Get("notFoundImage"))
// return
}
// klu clockin
if typeAbsensi == "clockin" {
// urlPath = "./selfie_attachment/" + subfolder + "/" + imgname
urlPath = config.Data.Get("clockInFolder") + subfolder + "/" + imgname
}
if typeAbsensi == "clockout" {
// urlPath = "./selfie_attachment/" + subfolder + "/" + imgname
urlPath = config.Data.Get("clockOutFolder") + subfolder + "/" + imgname
}
if typeAbsensi == "cuti" {
// urlPath = "./cuti/" + subfolder + "/" + imgname
urlPath = config.Data.Get("cutiFolder") + subfolder + "/" + imgname
}
if typeAbsensi == "ijin" {
// urlPath = "./ijin/" + subfolder + "/" + imgname
urlPath = config.Data.Get("ijinFolder") + subfolder + "/" + imgname
}
_, err := os.ReadFile(urlPath)
// gambar tidak ditemukan akan return image not found
if err != nil {
// w.Write([]byte("Invalid Attachment Clock In"))
// return
http.ServeFile(w, r, config.Data.Get("notFoundImage"))
return
}
http.ServeFile(w, r, urlPath)
})
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
router.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)