Skip to content

Commit

Permalink
.fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
WangNingkai committed Nov 6, 2018
1 parent bfc5390 commit 343ed5f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function show(Request $request)
}
});
if (!$file) abort(404);
if (isset($file['folder'])) abort(403);
if (array_has($file, 'folder')) abort(403);
$file['download'] = $file['@microsoft.graph.downloadUrl'];
$patterns = $this->show;
foreach ($patterns as $key => $suffix) {
Expand Down
44 changes: 25 additions & 19 deletions app/Http/Controllers/OneDriveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function listChildrenByPath($path = '/')
*/
public function getNextLinkList($list, &$result = [])
{
if (isset($list['@odata.nextLink'])) {
if (array_has($list, '@odata.nextLink')) {
$endpoint = str_after($list['@odata.nextLink'], Constants::REST_ENDPOINT . Constants::API_VERSION);
$response = $this->request('get', $endpoint);
$data = json_decode($response->getBody()->getContents(), true);
Expand Down Expand Up @@ -294,6 +294,8 @@ public function deleteItem($itemId, $eTag)
$statusCode = $response->getStatusCode();
if ($statusCode == 204) {
return $this->response(['deleted' => true]);
} else {
return $this->handleResponse($response);
}
} else {
return $response;
Expand Down Expand Up @@ -408,6 +410,8 @@ public function deletePermission($itemId, $permissionId)
$statusCode = $response->getStatusCode();
if ($statusCode == 204) {
return $this->response(['deleted' => true]);
} else {
return $this->handleResponse($response);
}
} else {
return $response;
Expand Down Expand Up @@ -485,26 +489,28 @@ public function uploadUrl($remote, $url)
if ($drive['code'] == 200) {
if ($drive['data']['driveType'] == 'business') {
return $this->response(['driveType' => $drive['data']['driveType']], 400, '企业账号无法使用离线下载');
}
$path = Tool::getAbsolutePath(dirname($remote));
// $pathId = $this->pathToItemId($path);
// $endpoint = "/me/drive/items/{$pathId}/children"; // by id
$handledPath = Tool::handleUrl(trim($path, '/'));
$graphPath = empty($handledPath) ? '/' : ":/{$handledPath}:/";
$endpoint = "/me/drive/root{$graphPath}children";
$headers = ['Prefer' => 'respond-async'];
$body = '{"@microsoft.graph.sourceUrl":"' . $url . '","name":"' . pathinfo($remote, PATHINFO_BASENAME) . '","file":{}}';
$response = $this->request('post', [$endpoint, $body, $headers]);
if ($response instanceof Response) {
$data = [
'redirect' => $response->getHeaderLine('Location')
];
return $this->response($data);
} else {
return $response;
$path = Tool::getAbsolutePath(dirname($remote));
// $pathId = $this->pathToItemId($path);
// $endpoint = "/me/drive/items/{$pathId}/children"; // by id
$handledPath = Tool::handleUrl(trim($path, '/'));
$graphPath = empty($handledPath) ? '/' : ":/{$handledPath}:/";
$endpoint = "/me/drive/root{$graphPath}children";
$headers = ['Prefer' => 'respond-async'];
$body = '{"@microsoft.graph.sourceUrl":"' . $url . '","name":"' . pathinfo($remote, PATHINFO_BASENAME) . '","file":{}}';
$response = $this->request('post', [$endpoint, $body, $headers]);
if ($response instanceof Response) {
$data = [
'redirect' => $response->getHeaderLine('Location')
];
return $this->response($data);
} else {
return $response;
}
}
} else {
return $drive;
}

}

/**
Expand Down Expand Up @@ -665,7 +671,7 @@ public function formatArray($response, $isList = true)
if ($isList) {
$items = [];
foreach ($response as $item) {
if (isset($item['file'])) $item['ext'] = strtolower(pathinfo($item['name'], PATHINFO_EXTENSION));
if (array_has($item, 'file')) $item['ext'] = strtolower(pathinfo($item['name'], PATHINFO_EXTENSION));
$items[$item['name']] = $item;
}
return $items;
Expand Down
21 changes: 11 additions & 10 deletions resources/views/one.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="col d-none d-md-block d-md-none">
<span class="pull-right">修改日期</span>
</div>
<div class="col d-none d-md-block d-md-none">
<div class="col">
<span class="pull-right">大小</span>
</div>
<div class="col">
Expand Down Expand Up @@ -138,7 +138,7 @@ class="fa fa-arrow-left"></i> 返回上一层</a></li>
<li class="list-group-item list-group-item-action">
<div class="row">
<div class="col" style="text-overflow:ellipsis;overflow:hidden;white-space:nowrap;">
@if(isset($item['folder']))
@if(array_has($item,'folder'))
<a href="{{ route('home',\App\Helpers\Tool::handleUrl($origin_path ? $origin_path.'/'.$item['name'] : $item['name'])) }}"
title="{{ $item['name'] }}">
<i class="fa fa-folder"></i> {{ $item['name'] }}
Expand All @@ -154,21 +154,22 @@ class="fa fa-arrow-left"></i> 返回上一层</a></li>
<span
class="pull-right">{{ date('Y-m-d H:i:s',strtotime($item['lastModifiedDateTime'])) }}</span>
</div>
<div class="col d-none d-md-block d-md-none">
<span class="pull-right">{{ \App\Helpers\Tool::convertSize($item['size']) }}</span>
<div class="col">
<span
class="pull-right">{{ array_has($item,'folder')? '-' : \App\Helpers\Tool::convertSize($item['size']) }}</span>
</div>
<div class="col">
<span class="pull-right">
@if(isset($item['folder']))
@if(array_has($item,'folder'))
<a href="javascript:void(0)"
data-clipboard-text="{{ route('home',\App\Helpers\Tool::handleUrl($origin_path ? $origin_path.'/'.$item['name'] : $item['name'])) }}"
class="clipboard" title="已复制" data-toggle="tooltip"
data-placement="right"><i class="fa fa-clipboard"></i></a>&nbsp;&nbsp;
@else
@if(isset($item['image']))
<a href="{{ route('view',\App\Helpers\Tool::handleUrl($origin_path ? $origin_path.'/'.$item['name'] : $item['name'])) }}"
data-fancybox="image-list"><i
class="fa fa-eye" title="查看"></i></a>&nbsp;&nbsp;
@if(array_has($item,'image')))
<a href="{{ route('view',\App\Helpers\Tool::handleUrl($origin_path ? $origin_path.'/'.$item['name'] : $item['name'])) }}"
data-fancybox="image-list"><i
class="fa fa-eye" title="查看"></i></a>&nbsp;&nbsp;
@endif
@if(session()->has('LogInfo') && \App\Helpers\Tool::canEdit($item) )
<a href="{{ route('file.update',$item['id']) }}"><i
Expand Down Expand Up @@ -207,7 +208,7 @@ class="clipboard"
<div class="card-body">
<div id="links">
@foreach($items as $item)
@if(isset($item['image']))
@if(array_has($item,'image'))
<a href="{{ route('view',$origin_path ? $origin_path.'/'.$item['name'] : $item['name']) }}"
title="{{ $item['name'] }}" data-gallery="image-list">
<img src="{{ route('thumb',['id'=>$item['id'],'size'=>'small']) }}"
Expand Down
20 changes: 10 additions & 10 deletions resources/views/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
<div class="card-header">
<div class="row">
<div class="col">
File
文件
</div>
<div class="col d-none d-md-block d-md-none">
<span class="pull-right">LastModifiedDateTime</span>
<span class="pull-right">最后修改时间</span>
</div>
<div class="col d-none d-md-block d-md-none">
<span class="pull-right">Size</span>
<div class="col">
<span class="pull-right">大小</span>
</div>
<div class="col d-none d-md-block d-md-none">
<span class="pull-right">Action</span>
<div class="col">
<span class="pull-right">操作</span>
</div>
</div>
</div>
Expand All @@ -39,14 +39,14 @@
<span
class="pull-right">{{ date('Y-m-d H:i:s',strtotime($item['lastModifiedDateTime'])) }}</span>
</div>
<div class="col d-none d-md-block d-md-none">
<div class="col">
<span class="pull-right">{{ \App\Helpers\Tool::convertSize($item['size']) }}</span>
</div>
<div class="col d-none d-md-block d-md-none">
<div class="col">
<span class="pull-right">
<a href="{{ route('search.show',$item['id']) }}"><i
class="fa fa-eye"
title="下载"></i></a>&nbsp;&nbsp;
class="fa fa-info"
title="详情"></i></a>&nbsp;&nbsp;
</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/show/audio.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class="fa fa-download"></i> 下载</a></div>
<label class="control-label">下载链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link1" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link1" class="form-control"
value="{{ route('download',\App\Helpers\Tool::handleUrl($origin_path)) }}">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/show/dash.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<label class="control-label">下载链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link1" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link1" class="form-control"
value="{{ route('download',\App\Helpers\Tool::handleUrl($origin_path)) }}">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand Down
6 changes: 3 additions & 3 deletions resources/views/show/image.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<label class="control-label">引用链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link1" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link1" class="form-control"
value="{{ route('view',\App\Helpers\Tool::handleUrl($origin_path)) }}">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand All @@ -32,7 +32,7 @@ class="input-group-text">复制</span></a>
<label class="control-label">Markdown链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link2" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link2" class="form-control"
value="![]({{ route('view',\App\Helpers\Tool::handleUrl($origin_path)) }})">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand All @@ -44,7 +44,7 @@ class="input-group-text">复制</span></a>
<label class="control-label">HTML链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link3" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link3" class="form-control"
value="<img src='{{ route('view',\App\Helpers\Tool::handleUrl($origin_path)) }}' />">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/show/video.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<label class="control-label">下载链接</label>
<div class="form-group">
<div class="input-group mb-3">
<input type="text" id="link1" class="form-control" aria-label="Amount (to the nearest dollar)"
<input type="text" id="link1" class="form-control"
value="{{ route('download',\App\Helpers\Tool::handleUrl($origin_path)) }}">
<div class="input-group-append">
<a href="javascript:void(0)" style="text-decoration: none" data-toggle="tooltip"
Expand Down

0 comments on commit 343ed5f

Please sign in to comment.