Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ RECAPTCHAV3_SECRET=
OTP_EXPIRY_MINUTES=5
TELEGRAM_BOT_TOKEN=

# Batas waktu pemanggilan HTTP keluar (detik), lihat config/http.php
HTTP_TIMEOUT=10
HTTP_CONNECT_TIMEOUT=5
HTTP_TTE_TIMEOUT=60

# Scribe / OpenAPI
# SCRIBE_AUTH_KEY=your-api-key-here
# pengaturan cache untuk API, jika ingin menonaktifkan cache, ubah API_CACHE_ENABLED menjadi false
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/SuratController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

namespace App\Http\Controllers\Api;

use App\Support\OutboundHttp;
use App\Enums\StatusVerifikasiSurat;
use App\Http\Controllers\Controller;
use App\Http\Resources\SuratResource;
use App\Models\DataDesa;
use App\Models\Penduduk;
use App\Models\Surat;
use Http;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function store(Request $request)
// jika api gabungan aktif, maka pengecekan penduduk melalui api gabungan
if ($this->isDatabaseGabungan()) {
$url = $this->settings['api_server_database_gabungan'].'/api/v1/opendk';
$response = Http::withHeaders([
$response = OutboundHttp::client()->withHeaders([
'Accept' => 'application/ld+json',
'Content-Type' => 'application/json; charset=utf-8',
'Authorization' => 'Bearer ' . ($this->settings['api_key_database_gabungan'] ?? ''),
Expand Down
64 changes: 3 additions & 61 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,30 @@

namespace App\Http\Controllers;

use App\Traits\KirimTrackPantau;
use App\Enums\JenisJabatan;
use App\Models\DataDesa;
use App\Models\DataUmum;
use App\Models\Event;
use App\Models\Jabatan;
use App\Models\Keluarga;
use App\Models\MediaSosial;
use App\Models\Navigation;
use App\Models\Penduduk;
use App\Models\Pengurus;
use App\Models\Profil;
use App\Models\Program;
use App\Models\SettingAplikasi;
use App\Models\SinergiProgram;
use App\Models\Slide;
use App\Models\TipePotensi;
use App\Services\DesaService;
use Exception;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\View;

class Controller extends BaseController
{
use KirimTrackPantau;

use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
Expand Down Expand Up @@ -151,60 +147,6 @@ public function __construct()
}
}

protected function kirimTrack()
{
if (config('app.demo') == true) { // jika posisi demo, matikan tracking
return;
}

if (cache()->get('track') != null && cache()->get('track') == date('Y m d')) {
return;
}

$host_pantau = config('app.host_pantau');
$data = [
'url' => url('/'),
'versi' => config('app.version'),
'jml_desa' => DataDesa::count(),
'desa' => json_encode(DataDesa::select(['desa_id', 'nama', 'sebutan_desa', 'path', 'website'])->get()),
'jumlahdesa_sinkronisasi' => DataDesa::count(),
'jumlah_penduduk' => Penduduk::where('status_dasar', 1)->count(),
'jumlah_keluarga' => Keluarga::count(),
'peta_wilayah' => $this->umum->path ?? '[[[[]]]]',
'batas_wilayah' => json_encode([
'bts_wil_utara' => $this->umum->bts_wil_utara,
'bts_wil_timur' => $this->umum->bts_wil_timur,
'bts_wil_selatan' => $this->umum->bts_wil_selatan,
'bts_wil_barat' => $this->umum->bts_wil_barat,
]),
'sebutan_wilayah' => $this->sebutan_wilayah,
'alamat' => $this->profil->alamat,
'jumlah_bantuan' => Program::count(),
'kode_kecamatan' => $this->profil->kecamatan_id,
'kode_kabupaten' => $this->profil->kabupaten_id,
'kode_provinsi' => $this->profil->provinsi_id,
'nama_kecamatan' => $this->profil->nama_kecamatan,
'nama_kabupaten' => $this->profil->nama_kabupaten,
'nama_provinsi' => $this->profil->nama_provinsi,
'nama_camat' => $this->nama_camat,
'lat' => $this->umum->lat,
'lng' => $this->umum->lng,
];

try {
$response = Http::withHeaders([
'token' => config('app.token_pantau'),
])->post($host_pantau.'track/opendk?token='.config('app.token_pantau'), $data);
cache()->put('track', date('Y m d'), 60 * 60 * 24);

return;
} catch (Exception $e) {
Log::notice($e);

return;
}
}

protected function isDatabaseGabungan()
{
return ($this->settings['sinkronisasi_database_gabungan'] ?? null) === '1';
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Data/DataDesaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

namespace App\Http\Controllers\Data;

use App\Support\OutboundHttp;
use App\Exports\ExportDataDesa;
use App\Http\Controllers\Controller;
use App\Http\Requests\DesaRequest;
Expand All @@ -49,7 +50,7 @@ class DataDesaController extends Controller
public function __construct()
{
parent::__construct();
$this->client = new Client();
$this->client = new Client(OutboundHttp::guzzleOptions());
}

/**
Expand Down
68 changes: 37 additions & 31 deletions app/Http/Controllers/Surat/PermohonanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use App\Models\DataDesa;
use App\Models\LogTte;
use App\Models\Surat;
use App\Support\OutboundHttp;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -223,22 +224,22 @@ public function passphrase(Request $request, $id)
{
$surat = Surat::findOrFail($id);

DB::beginTransaction();

$client = new \GuzzleHttp\Client([
// Panggilan ke server TTE dilakukan di luar transaksi DB agar server TTE yang lambat
// tidak menahan transaksi database.
$client = new \GuzzleHttp\Client(OutboundHttp::tteGuzzleOptions([
'base_uri' => $this->settings['tte_api'],
'auth' => [
$this->settings['tte_username'],
$this->settings['tte_password'],
],
]);
]));

try {
$file_path = public_path("storage/surat/{$surat->file}");
$width = 90;
$height = 90;
$tag = '[qr_camat]';
$file_path = public_path("storage/surat/{$surat->file}");
$width = 90;
$height = 90;
$tag = '[qr_camat]';

try {
$response = $client->post('api/sign/pdf', [
'headers' => ['X-Requested-With' => 'XMLHttpRequest'],
'multipart' => [
Expand All @@ -252,41 +253,46 @@ public function passphrase(Request $request, $id)
['name' => 'tag_koordinat', 'contents' => $tag],
],
]);

$surat->update([
'status' => StatusSurat::Arsip,
'log_verifikasi' => LogVerifikasiSurat::SudahTTE,
]);

DB::commit();

// overwrite dokumen lama dengan response dari bsre
if ($response->getStatusCode() == 200) {
$file = fopen($file_path, 'wb');
fwrite($file, $response->getBody()->getContents());
fclose($file);
}

return $this->response([
'status' => true,
'pesan_error' => 'success',
'jenis' => 'success',
]);
} catch (ClientException $e) {
Log::error('Permohonan Surat TTE signing failed', [
'error' => $e->getMessage(),
'user_id' => auth()->id(),
'surat_id' => $id,
]);

DB::rollback();

return $this->response([
'status' => false,
'pesan_error' => $e->getMessage(),
'jenis' => 'ClientException',
]);
}

DB::beginTransaction();
try {
$surat->update([
'status' => StatusSurat::Arsip,
'log_verifikasi' => LogVerifikasiSurat::SudahTTE,
]);

DB::commit();
} catch (\Throwable $e) {
DB::rollBack();

throw $e;
}

// overwrite dokumen lama dengan response dari bsre
if ($response->getStatusCode() == 200) {
$file = fopen($file_path, 'wb');
fwrite($file, $response->getBody()->getContents());
fclose($file);
}

return $this->response([
'status' => true,
'pesan_error' => 'success',
'jenis' => 'success',
]);
}

protected function response($notif = [])
Expand Down
64 changes: 3 additions & 61 deletions app/Http/Middleware/GlobalShareMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@

namespace App\Http\Middleware;

use App\Traits\KirimTrackPantau;
use App\Enums\JenisJabatan;
use App\Models\DataDesa;
use App\Models\DataUmum;
use App\Models\Jabatan;
use App\Models\Keluarga;
use App\Models\Penduduk;
use App\Models\Pengurus;
use App\Models\Profil;
use App\Models\Program;
use App\Models\SettingAplikasi;
use App\Models\TipePotensi;
use App\Models\Widget;
use App\Services\DesaService;
use Closure;
use Exception;
use Illuminate\Support\Facades\View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class GlobalShareMiddleware
{
use KirimTrackPantau;

protected $akun_camat;

protected $akun_sekretaris;
Expand Down Expand Up @@ -134,58 +130,4 @@ private function widgetAktif()
return $item;
});
}

protected function kirimTrack()
{
if (config('app.demo') == true) { // jika posisi demo, matikan tracking
return;
}

if (cache()->get('track') != null && cache()->get('track') == date('Y m d')) {
return;
}

$host_pantau = config('app.host_pantau');
$data = [
'url' => url('/'),
'versi' => config('app.version'),
'jml_desa' => DataDesa::count(),
'desa' => json_encode(DataDesa::select(['desa_id', 'nama', 'sebutan_desa', 'path', 'website'])->get()),
'jumlahdesa_sinkronisasi' => DataDesa::count(),
'jumlah_penduduk' => Penduduk::where('status_dasar', 1)->count(),
'jumlah_keluarga' => Keluarga::count(),
'peta_wilayah' => $this->umum->path ?? '[[[[]]]]',
'batas_wilayah' => json_encode([
'bts_wil_utara' => $this->umum->bts_wil_utara,
'bts_wil_timur' => $this->umum->bts_wil_timur,
'bts_wil_selatan' => $this->umum->bts_wil_selatan,
'bts_wil_barat' => $this->umum->bts_wil_barat,
]),
'sebutan_wilayah' => $this->sebutan_wilayah,
'alamat' => $this->profil->alamat,
'jumlah_bantuan' => Program::count(),
'kode_kecamatan' => $this->profil->kecamatan_id,
'kode_kabupaten' => $this->profil->kabupaten_id,
'kode_provinsi' => $this->profil->provinsi_id,
'nama_kecamatan' => $this->profil->nama_kecamatan,
'nama_kabupaten' => $this->profil->nama_kabupaten,
'nama_provinsi' => $this->profil->nama_provinsi,
'nama_camat' => $this->nama_camat,
'lat' => $this->umum->lat,
'lng' => $this->umum->lng,
];

try {
$response = Http::withHeaders([
'token' => config('app.token_pantau'),
])->post($host_pantau . 'track/opendk?token=' . config('app.token_pantau'), $data);
cache()->put('track', date('Y m d'), 60 * 60 * 24);

return;
} catch (Exception $e) {
Log::notice($e);

return;
}
}
}
8 changes: 4 additions & 4 deletions app/Services/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Services;

use App\Support\OutboundHttp;
use App\Models\SettingAplikasi;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
Expand All @@ -26,7 +26,7 @@ public function __construct()
public function register($data)
{

$response = Http::withHeaders([
$response = OutboundHttp::client()->withHeaders([
'X-Requested-With' => 'XMLHttpRequest',
])->timeout(10)->connectTimeout(5)->attach(
'permohonan',
Expand Down Expand Up @@ -67,7 +67,7 @@ public function register($data)

public function terdaftar($kode_kecamatan)
{
$response = Http::withHeaders([
$response = OutboundHttp::client()->withHeaders([
'Authorization' => 'Bearer ' . $this->setting->layanan_opendesa_token,
'X-Requested-With' => 'XMLHttpRequest',
])->timeout(10)->connectTimeout(5)->post("{$this->server}/api/v1/pelanggan/terdaftar-kecamatan", [
Expand All @@ -92,7 +92,7 @@ public function terdaftar($kode_kecamatan)

public function getFormRegister()
{
$response = Http::withHeaders([
$response = OutboundHttp::client()->withHeaders([
'Authorization' => 'Bearer ' . $this->setting->layanan_opendesa_token,
'X-Requested-With' => 'XMLHttpRequest',
])->timeout(10)->connectTimeout(5)->get("{$this->server}/api/v1/pelanggan/form-register-kecamatan");
Expand Down
Loading
Loading