65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2023-2024 美天智能科技
|
|
* @author 李志强
|
|
* @link http://www.meteteme.com
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace app\apiout\controller;
|
|
|
|
use app\apiout\BaseController;
|
|
use think\facade\Db;
|
|
use think\Response;
|
|
use app\model\PicbedFolder as PicbedFolderList;
|
|
|
|
class Index extends BaseController
|
|
{
|
|
// 推送数据
|
|
public function pullart()
|
|
{
|
|
// 允许来自任何来源的跨域请求
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
// 获取请求中的 folder 参数
|
|
$folderId = $this->request->get('folder');
|
|
|
|
$query = Db::name('PicbedImages');
|
|
|
|
// 根据 folderId 判断是否筛选
|
|
if ($folderId !== 'all') {
|
|
$query->where('folder', $folderId); // 筛选条件
|
|
}
|
|
|
|
$images = $query->order('id', 'desc')
|
|
->select()
|
|
->toArray();
|
|
|
|
// 获取当前请求的域名
|
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$host = $_SERVER['HTTP_HOST'];
|
|
$baseUrl = $protocol . '://' . $host;
|
|
|
|
$images = array_map(function ($image) use ($baseUrl) {
|
|
return [
|
|
'id' => $image['id'], // 新增 id
|
|
'name' => htmlspecialchars($image['name'], ENT_QUOTES),
|
|
'path' => $baseUrl . '/' . $image['path'],
|
|
'folder' => $image['folder']
|
|
];
|
|
}, $images);
|
|
|
|
return json(['code' => 0, 'msg' => '', 'data' => $images]);
|
|
}
|
|
|
|
//获取文件夹目录
|
|
public function getpicbedfolder()
|
|
{
|
|
$folder = PicbedFolderList::field('id, admin_id, name, sort')
|
|
->where('delete_time', null)
|
|
->where('status', '<>', 2)
|
|
->select();
|
|
return json(['code' => 0, 'msg' => '', 'data' => $folder]);
|
|
}
|
|
} |