156 lines
4.4 KiB
PHP
156 lines
4.4 KiB
PHP
<?php
|
|
// require __DIR__ . '/../vendor/autoload.php';
|
|
// use Aws\S3\S3Client;
|
|
// use Aws\Exception\AwsException;
|
|
|
|
// header("Content-Type: application/zip");
|
|
// header("Content-Disposition: attachment; filename=download.zip");
|
|
|
|
// $product = $_GET['product_code'] ?? '';
|
|
// $version = $_GET['sw_version'] ?? '';
|
|
|
|
// if (!$product || !$version) {
|
|
// http_response_code(400);
|
|
// echo "필수값 없음";
|
|
// exit;
|
|
// }
|
|
|
|
// // === DB 연결 ===
|
|
// $conn = new mysqli("localhost", "egbim", "baron3840!!", "egbim");
|
|
// mysqli_set_charset($conn, "utf8mb4");
|
|
|
|
// $res = $conn->query("SELECT filename, original_name, filepath FROM deploy_files
|
|
// WHERE product_code='".$conn->real_escape_string($product)."'
|
|
// AND sw_version='".$conn->real_escape_string($version)."'
|
|
// AND deleted=0");
|
|
// $files = $res->fetch_all(MYSQLI_ASSOC);
|
|
|
|
// if (empty($files)) {
|
|
// echo "파일 없음";
|
|
// exit;
|
|
// }
|
|
|
|
// // === S3 Client ===
|
|
// $s3 = new S3Client([
|
|
// 'version' => 'latest',
|
|
// 'region' => 'auto',
|
|
// 'endpoint'=> 'https://81fa2d48964d31dd0da9558f9ce601d1.r2.cloudflarestorage.com',
|
|
// 'credentials' => [
|
|
// 'key' => '11d7027f505658acb3aeb40c3955a206',
|
|
// 'secret' => '65a78f6c582e0bdfccc2f431fc7b7be2ba11f999f0a8a87142011eac8b84761f',
|
|
// ]
|
|
// ]);
|
|
|
|
// // === 임시 ZIP 파일 ===
|
|
// $tmpZip = tempnam(sys_get_temp_dir(), "zip");
|
|
// $zip = new ZipArchive();
|
|
// $zip->open($tmpZip, ZipArchive::OVERWRITE);
|
|
|
|
// foreach ($files as $f) {
|
|
// $key = $f['filepath']; // 예: 999/1.4.6/releasenote_999_1.4.6.md
|
|
// $saveName = $f['original_name'] ?: basename($f['filename']);
|
|
|
|
// try {
|
|
// $obj = $s3->getObject([
|
|
// 'Bucket' => 'baron-software-release',
|
|
// 'Key' => $key
|
|
// ]);
|
|
// $content = (string)$obj['Body'];
|
|
|
|
// if ($content !== '') {
|
|
// $zip->addFromString($saveName, $content);
|
|
// }
|
|
// } catch (AwsException $e) {
|
|
// error_log("다운로드 실패: $key - " . $e->getMessage());
|
|
// }
|
|
// }
|
|
|
|
// $zip->close();
|
|
|
|
// // === ZIP 출력 ===
|
|
// readfile($tmpZip);
|
|
// unlink($tmpZip);
|
|
// exit;
|
|
?>
|
|
|
|
<?php
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
use Aws\S3\S3Client;
|
|
use Aws\Exception\AwsException;
|
|
|
|
ini_set('display_errors', 0);
|
|
error_reporting(0);
|
|
|
|
$product = $_GET['product_code'] ?? '';
|
|
$version = $_GET['sw_version'] ?? '';
|
|
|
|
if (!$product || !$version) {
|
|
http_response_code(400);
|
|
exit("필수값 없음");
|
|
}
|
|
|
|
// === DB 연결 ===
|
|
$conn = new mysqli("localhost", "egbim", "baron3840!!", "egbim");
|
|
mysqli_set_charset($conn, "utf8mb4");
|
|
|
|
$sql = "SELECT filename, original_name, filepath, release_date
|
|
FROM deploy_files
|
|
WHERE product_code=? AND sw_version=? AND deleted=0";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("ss", $product, $version);
|
|
$stmt->execute();
|
|
$res = $stmt->get_result();
|
|
$files = $res->fetch_all(MYSQLI_ASSOC);
|
|
$stmt->close();
|
|
$conn->close();
|
|
|
|
if (empty($files)) {
|
|
http_response_code(404);
|
|
exit("파일 없음");
|
|
}
|
|
|
|
// === S3 Client ===
|
|
$s3 = new S3Client([
|
|
'version' => 'latest',
|
|
'region' => 'auto',
|
|
'endpoint'=> 'https://81fa2d48964d31dd0da9558f9ce601d1.r2.cloudflarestorage.com',
|
|
'credentials' => [
|
|
'key' => '11d7027f505658acb3aeb40c3955a206',
|
|
'secret' => '65a78f6c582e0bdfccc2f431fc7b7be2ba11f999f0a8a87142011eac8b84761f',
|
|
]
|
|
]);
|
|
|
|
// === ZIP 생성 ===
|
|
$tmpZip = tempnam(sys_get_temp_dir(), "zip");
|
|
$zip = new ZipArchive();
|
|
$zip->open($tmpZip, ZipArchive::OVERWRITE);
|
|
|
|
foreach ($files as $f) {
|
|
$key = $f['filepath'];
|
|
$saveName = $f['original_name'] ?: basename($f['filename']);
|
|
$bucket = $f['release_date'] ? 'baron-software-release' : 'baron-software-test';
|
|
|
|
try {
|
|
$obj = $s3->getObject([
|
|
'Bucket' => $bucket,
|
|
'Key' => $key
|
|
]);
|
|
$content = (string)$obj['Body'];
|
|
$zip->addFromString($saveName, $content);
|
|
} catch (AwsException $e) {
|
|
// 실패한 파일은 스킵 (ZIP은 정상 유지)
|
|
}
|
|
}
|
|
$zip->close();
|
|
|
|
// === ZIP 전송 ===
|
|
if (ob_get_level()) ob_end_clean();
|
|
header("Content-Type: application/zip");
|
|
header("Content-Disposition: attachment; filename=\"{$product}_{$version}.zip\"");
|
|
header("Content-Length: " . filesize($tmpZip));
|
|
|
|
readfile($tmpZip);
|
|
unlink($tmpZip);
|
|
exit;
|
|
|