mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2025-01-31 13:12:47 +08:00
remove safety check and better md support
This commit is contained in:
parent
d984e11424
commit
12c0b21e8e
@ -2,6 +2,6 @@
|
||||
|
||||
const APP_NAME = "ph-Bookshelf";
|
||||
|
||||
const VERSION = "0.5.0-alpha10";
|
||||
const VERSION = "0.5.0-alpha11";
|
||||
const CHANNEL = "suk-ws";
|
||||
const BRANCH = "config-v2.0";
|
||||
|
@ -18,18 +18,10 @@ class Data {
|
||||
|
||||
public static function get(string $id): Data|false {
|
||||
$path = realpath(self::root.$id);
|
||||
if ($path !== false && self::checkSafety($path)) {
|
||||
if ($path !== false) {
|
||||
return new Data($path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function getRealRootPath(): string {
|
||||
return realpath(self::root);
|
||||
}
|
||||
|
||||
private static function checkSafety (string $checked): bool {
|
||||
return str_starts_with(realpath($checked), self::getRealRootPath());
|
||||
}
|
||||
|
||||
}
|
28
src/Utils/FileMime.php
Normal file
28
src/Utils/FileMime.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Utils;
|
||||
|
||||
use Elephox\Mimey\MimeMappingBuilder;
|
||||
use Elephox\Mimey\MimeTypes;
|
||||
|
||||
class FileMime {
|
||||
|
||||
private static MimeTypes $mimes;
|
||||
|
||||
static function init (): void {
|
||||
$builder = MimeMappingBuilder::create();
|
||||
$builder->add('text/markdown', 'md');
|
||||
$builder->add('text/markdown', 'mkd');
|
||||
$builder->add('text/markdown', 'mdwn');
|
||||
$builder->add('text/markdown', 'mdown');
|
||||
$builder->add('text/markdown', 'mdtxt');
|
||||
$builder->add('text/markdown', 'mdtext');
|
||||
$builder->add('text/markdown', 'markdown');
|
||||
self::$mimes = new MimeTypes($builder->getMapping());
|
||||
}
|
||||
|
||||
public static function fromExtension($ext): string {
|
||||
return self::$mimes->getMimeType($ext) ?: "application/octet-stream";
|
||||
}
|
||||
|
||||
} FileMime::init();
|
@ -27,7 +27,7 @@ class PageParse {
|
||||
exit("File Can't Read!");
|
||||
}
|
||||
// 判定文件类型
|
||||
$fileMime = MimeType::fromExtension($fileExtension)->getValue();
|
||||
$fileMime = FileMime::fromExtension($fileExtension);
|
||||
// 文件类型是二进制流。设置为utf8编码(支持中文文件名称)
|
||||
header('Content-type:'.$fileMime.'; charset=utf-8');
|
||||
header("Access-Control-Allow-Origin: * ");
|
||||
|
Loading…
Reference in New Issue
Block a user