generated from liutk/owl-admin-base
Update
parent
02e8fa4196
commit
accf828d5b
|
|
@ -85,15 +85,18 @@ class AppVersionController extends AdminController
|
|||
amis()->FileControl('android[wgt_url]', __('app_version.wgt_url'))
|
||||
->accept('.wgt')
|
||||
->useChunk(false)
|
||||
->receiver($this->uploadFilePath().'?full-url=1')
|
||||
->visibleOn('${AND(os == "'.AppOs::Android->value.'", update_strategy == "wgt")}'),
|
||||
amis()->FileControl('android[apk_url]', __('app_version.apk_url'))
|
||||
->accept('.apk')
|
||||
->useChunk(false)
|
||||
->receiver($this->uploadFilePath().'?full-url=1')
|
||||
->visibleOn('${os == "'.AppOs::Android->value.'"}'),
|
||||
|
||||
amis()->FileControl('ios[wgt_url]', __('app_version.wgt_url'))
|
||||
->accept('.wgt')
|
||||
->useChunk(false)
|
||||
->receiver($this->uploadFilePath().'?full-url=1')
|
||||
->visibleOn('${AND(os == "'.AppOs::Ios->value.'", update_strategy == "wgt")}'),
|
||||
amis()->TextControl('ios[apk_url]', '苹果应用地址')
|
||||
->placeholder('苹果应用地址')
|
||||
|
|
|
|||
|
|
@ -106,29 +106,12 @@ class AppVersionService extends BaseService
|
|||
|
||||
$model = $this->getModel();
|
||||
|
||||
$instance = new $model($data);
|
||||
$model::create(array_merge($data, [
|
||||
'apk_url' => $apkUrl,
|
||||
'wgt_url' => $wgtUrl,
|
||||
]));
|
||||
|
||||
try {
|
||||
$filename = $data['name'].'_'.time();
|
||||
if ($extension = pathinfo($apkUrl, PATHINFO_EXTENSION)) {
|
||||
$filename .= '.'.$extension;
|
||||
}
|
||||
$instance->apk_url = $this->saveUploadedFile($apkUrl, "app-versions/{$filename}");
|
||||
} catch (FileNotFoundException $e) {
|
||||
admin_abort('全量包未找到,请重新上传');
|
||||
}
|
||||
|
||||
try {
|
||||
$filename = $data['name'].'_'.time();
|
||||
if ($extension = pathinfo($wgtUrl, PATHINFO_EXTENSION)) {
|
||||
$filename .= '.'.$extension;
|
||||
}
|
||||
$instance->wgt_url = $this->saveUploadedFile($wgtUrl, "app-versions/{$filename}");
|
||||
} catch (FileNotFoundException $e) {
|
||||
admin_abort('增量包未找到,请重新上传');
|
||||
}
|
||||
|
||||
return $instance->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($primaryKey, $data): bool
|
||||
|
|
@ -191,45 +174,10 @@ class AppVersionService extends BaseService
|
|||
}
|
||||
|
||||
$instance = $this->query()->whereKey($primaryKey)->firstOrFail();
|
||||
$instance->fill($data);
|
||||
|
||||
try {
|
||||
$filename = $data['name'].'_'.time();
|
||||
if ($extension = pathinfo($apkUrl, PATHINFO_EXTENSION)) {
|
||||
$filename .= '.'.$extension;
|
||||
}
|
||||
$instance->apk_url = $this->saveUploadedFile($apkUrl, "app-versions/{$filename}");
|
||||
} catch (FileNotFoundException $e) {
|
||||
admin_abort('全量包未找到,请重新上传');
|
||||
}
|
||||
|
||||
try {
|
||||
$filename = $data['name'].'_'.time();
|
||||
if ($extension = pathinfo($wgtUrl, PATHINFO_EXTENSION)) {
|
||||
$filename .= '.'.$extension;
|
||||
}
|
||||
$instance->wgt_url = $this->saveUploadedFile($wgtUrl, "app-versions/{$filename}");
|
||||
} catch (FileNotFoundException $e) {
|
||||
admin_abort('增量包未找到,请重新上传');
|
||||
}
|
||||
|
||||
return $instance->save();
|
||||
}
|
||||
|
||||
protected function saveUploadedFile(string $from, string $to): string
|
||||
{
|
||||
if ($from === '' || preg_match('/^https?:\/\//', $from)) {
|
||||
return $from;
|
||||
}
|
||||
|
||||
$disk = Storage::disk(Admin::config('admin.upload.disk'));
|
||||
|
||||
if (! $disk->exists($from)) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
$disk->move($from, $to);
|
||||
|
||||
return $disk->url($to);
|
||||
$instance->update(array_merge($data, [
|
||||
'apk_url' => $apkUrl,
|
||||
'wgt_url' => $wgtUrl,
|
||||
]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ Route::group([
|
|||
$router->resource('app-versions', AppVersionController::class)->names('app_versions');
|
||||
|
||||
// 修改上传
|
||||
$router->post('upload_file', [\App\Admin\Controllers\IndexController::class, 'uploadFile']);
|
||||
$router->any('upload_file', [\App\Admin\Controllers\IndexController::class, 'uploadFile']);
|
||||
$router->post('upload_image', [\App\Admin\Controllers\IndexController::class, 'uploadImage']);
|
||||
$router->post('upload_rich', [\App\Admin\Controllers\IndexController::class, 'uploadRich']);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ trait UploadTrait
|
|||
return $this->response()->fail(__('admin.upload_file_error'));
|
||||
}
|
||||
|
||||
$path = $file->storeAs(Admin::config('admin.upload.tem_directory.'.$type).'/'.date('Ymd'), $this->hashFilename($file), Admin::config('admin.upload.disk'));
|
||||
$path = $file->storeAs(Admin::config('admin.upload.directory.'.$type).'/'.date('Ymd'), $this->hashFilename($file), Admin::config('admin.upload.disk'));
|
||||
if (request()->has('full-url')) {
|
||||
$path = Storage::disk(Admin::config('admin.upload.disk'))->url($path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue