Code Monkey home page Code Monkey logo

odindex's Introduction

OdIndex

SomeBottle's Onedrive Folder Index transplanted from Heymind.

Show

最近发现Heymind写的Cloudflare Worker版的oneindex很好用,遂移植了一个php版本.(2.0进行了大更新)

原Heymind的Cloudflare Workers版OnedriveIndex使用MIT协议.

前言

这只是通过调用api实现的onedrive文件列表程序,并不提供任何账号相关的内容。如果有条件,请花钱支持一下巨硬微软。

Features & Drawbacks

  • 自动更新token(除非非常非常久没访问)
  • 可以进行转发下载(过服务器流量的那种[建议是国外服务器],但能快很多)
  • 简单配置后可以搭配世纪互联版Onedrive
  • 鼠标悬停预览
  • 使用github-markdown-css进行markdown的渲染
  • 使用Prism.js来渲染简单的代码高亮
  • 支持站点非根目录
  • autoCache文件缓存
  • 支持缩略图获取
  • 支持密码保护目录以及目录下面的文件
  • 没有文件上传功能
  • 支持的格式预览:ogg,mp3,wav,m4a,mp4,webm,jpg,jpeg,png,gif,webp,md,markdown,txt,docx,pptx,xlsx,doc,ppt,xls,js,html,json,css
  • 支持无目录模式
  • 支持以纯json格式返回

To-do list

  • autoCache 文件缓存
  • 支持根目录文件列表
  • 文件简单预览
  • 文件复杂预览
  • 模板系统
  • 翻页支持

Deployment

  1. 准备一个网站服务器,把仓库中odproxy.php , index.php , template.html丢进去

  2. 按照Beetcb的方式获取refresh_token

  3. 在index.php设置相关参数

  4. 设置伪静态(重定向规则):(可选)

if (!-f $request_filename){
  set $rule_0 1$rule_0;
}
if (!-d $request_filename){
  set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
  rewrite ^/(.*)$ /?/$1 last;
}

如果是非根目录,要在重定向规则上作相应调整

Thumbnail缩略图

对于图片文件,可以直接获取不同尺寸的缩略图。 比如:https://xxx/pics/loli.png?thumbnail=medium
最常用值有small,medium,large

Readme文件

在你需要展示说明文件的目录下放入readme.md文件,会自动进行解析并展示在该目录的文件列表下.

Password

你配置的地方下创建密码配置文件,如图:

ExamplePwd

一行表示一个目录保护规则,格式是/目录路径 32位md5加密后的密码

注意的是目录路径末尾不需要/

比如我要保护/Video/*下的内容,密码md5是e10adc3949ba59abbe56e057f20f883e,则规则写为
/Video e10adc3949ba59abbe56e057f20f883e

PS:这个规则可以保护目录及目录下的所有子目录和文件,利用了目录对比。因为获取密码有了额外的资源消耗,你可以在配置里关掉密码保护功能。

Template.html

这是自OdIndex2.0之后有的模板文件。

  1. 形如{{xxx}}的是模板提取符:
    {{Body}}{{BodyEnd}} 之间是OdIndex主体模板
    {{PathSingle}}{{PathSingleEnd}} 之间是目录定位链接单体模板
    {{ItemSingle}}{{ItemSingleEnd}} 之间是单个列表中的项目的模板
    {{PaginationSingle}}{{PaginationSingleEnd}} 之间是列表中的翻页部分的模板
    {{PaginationPrev}}{{PaginationPrevEnd}} 之间是翻页部分后退按钮的模板
    {{PaginationNext}}{{PaginationNextEnd}} 之间是翻页部分前进按钮的模板
    {{PreviewBody}}{{PreviewBodyEnd}} 之间是预览的主体模板
    {{ImgPreview}}{{ImgPreviewEnd}} 之间是图片预览的内容模板
    {{AudioPreview}}{{AudioPreviewEnd}} 之间是音频预览的内容模板
    {{VideoPreview}}{{VideoPreviewEnd}} 之间是视频预览的内容模板
    {{TxtPreview}}{{TxtPreviewEnd}} 之间是文本预览的内容模板
    {{MDPreview}}{{MDPreviewEnd}} 之间是markdown预览的内容模板
    {{CodePreview}}{{CodePreviewEnd}} 之间是代码预览的内容模板
    {{OfficePreview}}{{OfficePreviewEnd}} 之间是Office文档的内容模板
    {{PasswordPage}}{{PasswordPageEnd}} 之间是密码提交页面模板

  2. 形如{[xxx]}的是模板替换符:
    {[Path]} 是当前的路径,替换后形如Video/ACG/
    {[HomePath]} 是主页路径
    {[PathItems]} 和前面的{{PathSingle}}相搭配,替换后是组装过后的目录定位整体
    {[Items]} 和前面的{{ItemSingle}}相搭配,替换后是组装后的文件列表
    {[Pagination]} 仅在{{Body}}中有用和前面的{{PaginationSingle}}相搭配,替换后是组装后的pagination翻页部分
    {[Prev]},{[Next]} 仅在{{PaginationSingle}}中有用 , 被替换为前进和后退按钮
    {[PrevLink]},{[NextLink]} 仅分别在{{PaginationPrev}}和{{PaginationNext}}中有用 , 被替换为前进和后退链接
    {[CurrentPage]} 仅在{{Body}}中有用 , 被替换为当前页码
    {[ReadmeFile]} 是当前目录下的readme文件的直链
    {[FolderLink]},{[FolderName]} 仅在{{PathSingle}}中有用 , 指定目录定位链接和目录名
    {[ItemLink]},{[ItemSize]},{[MimeIcon]},{[ItemName]} 仅在{{ItemSingle}}中有用 , 指定单个文件的链接、大小(bytes)、Mime图标标识、名字
    {[FileName]} 仅在{{PreviewBody}}中可用 , 替换为当前预览的文件名
    {[PreviewContent]} 仅在{{PreviewBody}}中可用 , 替换为对应的内容模板
    {[CreatedDateTime]} 仅在{{PreviewBody}}和{{ItemSingle}}中可用 , 替换为当前文件的创建日期时间
    {[LastModifiedDateTime]} 仅在{{PreviewBody}}和{{ItemSingle}}中可用 , 替换为当前文件的最后修改日期时间
    {[MimeType]} 仅在{{PreviewBody}}和{{ItemSingle}}中可用 , 替换为当前文件mime属性
    {[FileRawUrl]} 仅在预览相关模板中可用 , 替换为文件直链
    {[PreviewUrl]} 仅在预览Office文档时可用 , 替换为在线预览链接
    {[FileContent]} 仅在{{TxtPreview}},{{MDPreview}},{{CodePreview}}中有用 , 替换为文件原内容
    {[PrismTag]} 仅在{{CodePreview}}中可用 , 替换为Prism代码高亮类型tag
    {[FolderMD5]} 仅在{{PasswordPage}}中可用 , 替换为表单目录md5

Config

$config = array(
	"refresh_token" => "",
	"client_id" => "",
	"client_secret" => "",
	"api_url" => "https://graph.microsoft.com/v1.0",
	"oauth_url" => "https://login.microsoftonline.com/common/oauth2/v2.0",
	"redirect_uri" => "http://localhost",
	'base' => '',
	'data_path' => 'data',
	'rewrite' => false, // 伪静态是否开启,如果网站服务器开启了伪静态请设置为true
	'site_path' => '',
	"cache" => array(
		'smart' => true,
		'expire' => 1800, /*In seconds*/
		'force' => false /*是否强制开启缓存*/
	),
	'queue' => array(
		'start' => true,/*防并发请求队列*/
		'max_num' => 15,/*队列中允许停留的最多请求数,其他请求直接返回服务繁忙*/
		'last_for' => 2700 /*In seconds*/
	),
	'service_busy' => 'https://fastly.jsdelivr.net/gh/SomeBottle/odindex/assets/unavailable.png',/*队列过多时返回的“服务繁忙”图片url*/
	'thumbnail' => true,
	'preview' => true,
	'max_preview_size' => 314572, /*最大支持预览的文件大小(in bytes)*/
	'preview_suffix' => ['ogg', 'mp3', 'wav', 'm4a', 'mp4', 'webm', 'jpg', 'jpeg', 'png', 'gif', 'webp', 'md', 'markdown', 'txt', 'docx', 'pptx', 'xlsx', 'doc', 'ppt', 'xls', 'js', 'html', 'json', 'css'],/*可预览的类型,只少不多*/
	'use_proxy' => false,
	'proxy_path' => false, /*代理程序url,false则用本目录下的*/
	'no_index' => false, /*关闭列表*/
	'no_index_print' => 'Static powered by OdIndex', /*关闭列表访问列表时返回什么*/
	'list_as_json' => false, /*改为返回json*/
	'pwd_cfg_path' => '.password', /*密码配置文件路径*/
	'pwd_protect' => true,/*是否采用密码保护,这会稍微多占用一些程序资源*/
	'pwd_cfg_update_interval' => 1200, /*密码配置文件本地缓存时间(in seconds)*/
	'pagination' => true, /*是否开启分页*/
	'items_per_page' => 20 /*每页的项目数量,用于分页(推荐设置为20-35)*/
);
  • base配置项用于规定展示onedrive根目录下哪个目录的内容.例如将你要展示列表的文件放在onedrive根目录下的Share目录里面base项配置为 "/Share" 即可,如果你要展示根目录的内容,请将base项设置为留空

  • preview配置项用来配置是否开启默认预览,开启之后点击列表中的文件会默认进入预览界面.preview_suffix是支持预览的文件格式,不建议修改.

  • site_path配置项是为了适应站点非根目录的,如果你的站点类似于https://xxx/ ,这一个配置项留空;如果你的站点类似于https://xxx/onedrive/ ,那么这个配置项你就要改成:

      'site_path'=>'/onedrive',  
      //末尾不要斜杠!  
  • 值得注意的是,rewrite=false(关闭重定向)时,site_path可以留空,用不着

  • 当你开启了重定向并设置了site_path,需要对应修改重定向规则:

    #(比如site_path设置为/test)  
    rewrite ^/(.*)$ /?/$1 last;  
    
    #改为
    
    rewrite ^/test/(.*)$ /test/?/$1 last;
    
    
  • use_proxy配置项用于启动转发下载,如果为true,调用直链时会自动用odproxy.php转发下载.

  • 如果odproxy.phpindex.php不是相同目录下的,需要配置**proxy_path**.例如https://xxx/odproxy.php .

  • rewrite配置项若设置为true,你必须配置伪静态(重定向规则);若设置为false,你可以用请求的方式访问.
    例如开了伪静态,你可以访问https://xxx/Document/ ,没有开伪静态,你需要访问https://xxx/?/Document/ 来进行访问。

  • data_path配置项指的是数据的储存目录,默认配置成data,OdIndex的部分数据就会储存在data目录下

  • no_index配置为true时,除了访问文件外一律返回no_index_print内的内容

  • list_as_json配置为true时,所有的返回内容都会变成JSON形式:

    正常返回:

    {
        "success": true,
        "currentPath": "",
        "currentPage": 1,
        "nextPageExist": false,
        "prevPageExist": false,
        "folders": [{
      	  "createdDateTime": "2021-04-24T03:51:36.99Z",
      	  "lastModifiedDateTime": "2021-04-27T11:17:31.457Z",
      	  "name": "Previews",
      	  "size": 117218729,
      	  "link": "Previews\/"
        }, {
      	  "createdDateTime": "2021-04-24T03:51:37.967Z",
      	  "lastModifiedDateTime": "2021-04-24T03:53:43.597Z",
      	  "name": "Protected",
      	  "size": 197107,
      	  "link": "Protected\/"
        }],
        "files": [{
      	  "createdDateTime": "2021-04-24T03:51:45.093Z",
      	  "lastModifiedDateTime": "2021-04-24T03:51:45.85Z",
      	  "mimeType": "image\/png",
      	  "name": "Potato.png",
      	  "size": 314,
      	  "link": "Potato.png?p=t"
        }, {
      	  "createdDateTime": "2021-04-24T03:51:44.83Z",
      	  "lastModifiedDateTime": "2021-04-24T03:59:19.71Z",
      	  "mimeType": "application\/octet-stream",
      	  "name": "readme.md",
      	  "size": 141,
      	  "link": "readme.md?p=t"
        }]
    }

    找不到文件/目录的返回:

    {"success":false,"msg":"Not found: \/Potato.jpg"}

    Json返回模式下不支持预览:

    {"success":false,"msg":"Preview not available under list_as_json Mode"}

    访问文件时的返回:

    {
        "success": true,
        "fileurl": "...",
        "createdDateTime": "2021-04-24T03:51:45.093Z",
        "lastModifiedDateTime": "2021-04-24T03:51:45.85Z",
        "mimeType": "image\/png"
    }
  • pwd_cfg_path是你的密码的配置文件路径,默认是.password,也就是列表根目录的.password文件.
    如果你想配置成在列表Test目录内的passwordconfig文件可以这样写:
    pwd_cfg_path=>'Test/passwordconfig',

  • pwd_protect如果设置为false会直接忽略密码配置,放行所有请求,但是能节省一定请求资源

  • pwd_cfg_update_interval密码配置文件缓存过期的时长,单位为秒。每次请求密码配置文件后配置文件会被暂时缓存在本地(以减少重复请求的情况),每隔这段时间进行重新请求而刷新。

  • pagination设置为true开启分页,每页展示的项目数量由**items_per_page决定,因为微软api的缺陷,建议把items_per_page设置为20-40**,太小了会增加请求负担,太大了会增加服务器处理负担

世纪互联

编辑头部config中**api_urloauth_url**内容为:

"api_url"=> "https://microsoftgraph.chinacloudapi.cn/v1.0", 
"oauth_url"=>"https://login.partner.microsoftonline.cn/common/oauth2/v2.0", 

Auto Cache (文件缓存)

"cache"=>array(
    'smart'=>true,
    'expire'=>1200, /*In seconds*/
    'force' => false /*是否强制开启缓存*/
),

AutoCache会在你的文件目录被大量访问时自动缓存目录,配置项只有以上三个。

  • smart 若为true则开启autoCache
  • expire 自动缓存开启后持续的时间,这段时间过去后缓存文件会被自动删除,一切恢复正常
  • 当**force**设为true时开启强制缓存,此时用户访问的页面都会被缓存,经过expire时间后缓存会自动清除

The Queue

'queue'=>array(
     'start'=>true,/*防并发请求队列*/
     'max_num'=>15,/*队列中允许停留的最多请求数,其他请求直接返回服务繁忙*/
     'last_for'=>2700 /*In seconds*/
),
'service_busy'=>'https://fastly.jsdelivr.net/gh/SomeBottle/odindex/assets/unavailable.png',

TheQueue会在游客对文件造成大量请求时防止并发情况出现,可以有效防止账户被微软限制.

  • max_num 是队列中存在的最多请求数,每请求一个未缓存页面、一个文件,在请求未完成之时全部当排队请求,而当排队请求的量超过了max_num,会直接返回服务繁忙,也就是service_busy的图片.

  • last_for 是队列模式开启后持续的时间,按秒计算.超过这个时间后一切会恢复正常.建议比AutoCache的设置更长一点.

Notice

  • 因为在密码缓存过期的时候服务器要进行重新请求,故此时访问OdIndex页面会比平常慢上一段时间。咱的建议是设置一个crontab任务,每间隔一段时间访问一下网页以及时刷新密码配置。

  • 访问目录时末尾要加上'/',如果访问 https://xxx/Document 会帮你重定向到 https://xxx/Document.

  • 如果特别特别久没有访问了,显示 Failed to get accesstoken. Maybe refresh_token expired ,需要更换refresh_token删掉生成的token.php,在index.php头部修改配置为自行重新获取的refreshtoken即可.

Thanks

Reference


UNDER MIT LICENSE.

odindex's People

Contributors

somebottle avatar zanjie1999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

odindex's Issues

又一些建议

  1. 图床功能

https://github.com/jialezi/oneindex-j
参见

但这个有点问题,有时不能成功上传,且路径太长,上传后路径类似

image/2020/12/06/aaa.jpg

2.可恢复的上传,

即大文件切片上传

可参见官方文档

3.离线下载

首页空白

按照步骤填写好了 refresh_token,唯一跟教程的区别是 redirect_url 填的是 http://localhost:3000

因为 http://localhost 一直是拒绝访问,所以加了端口号,index.php 里也相应增加了 3000 端口号。

首页打开是完全空白的。控制台也没有报错

一些建议

首先我想说这真的是一个很好的项目。
但是尚有可改进之处。

首先就是我认为原版的那个主题太过于单调了。而且看起来也不是很美观。我试过了很多的oneindex ,发现spencerwooo的项目
看起来很好看,希望作者能够使用它的CSS。

其次就是虽然实现了一些基本的文件预览功能。但是大部分的文件还是不能预览。建议参考
https://github.com/jialezi/oneindex-j
可以实现docx pptx 等文件的预览,而且不消耗服务器的流量。将这个预览方式的文件类型支持列表中添加.zip .rar 等,便可以实现通过Onedrive 的文件预览

参考官方文档。

希望采纳,我很需要这些功能。

There is no password protect

In Heymind version we can inout user name and password for our index site but in your php script i can't find any:(
please add this feature

[Solved]无法使用,提示Failed to get accesstoken. Maybe refresh_token expired.

已经阅读须知并且改了权限,但是仍然报这个错误。

折叠图片

image

已经通过描述的方法获取到了两个token,但是输入以后仍然无法使用

折叠图片

image
image

使用的是vultr的vps,也不会存在无法访问GitHub的问题
在手动创建token.php以后报错消失但是变白屏,是不是可以通过手动修改token.php的方法来避开报错?

补充:在使用小工具microsoft-graph-api-auth获取token时,于步骤4. Authorize for code报错:AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application: '2385e6be-54f6-4b1e-ade6-bcc705563fac'.
已经在Azure Portal里配置相应的URI

We are unable to fulfill your request

i have error when authorized ondrive account please help
invalid_request: The provided value for the input parameter 'redirect_uri' is not valid. The expected value is a URI which matches a redirect URI registered for this client application.

等着列出子项api支持skip分页的那一天

之前翻看文档发现分页正好有个skip查询参数可以跳过指定项目数,结果当我在拉取onedrive目录子项的时候竟然提示不支持
导致现在我只能用默认的top参数和skipToken进行分页,这样的问题是指定翻到哪一页时需要进行遍历请求,我能做的只是分担一部分分页工作给本地服务器以减少请求压力

但是嘛...真的好想微软Graph支持列出子项这个api使用skip参数啊啊啊!.....((/- -)/

致看到这条issue的各位,哪天微软支持了记得回复一下,咱会看到的,谢谢了!

请问下密码不起作用怎么办?

Index.php 配置:

'pwd_cfg_path' => '.password', 
'pwd_protect' => true,

.password 也放在根目录了

是用宝塔界面部署的

但是密码不起作用

谢谢

能不能简化下获取值的方式?

能不能像zfile或者onemanager那样获取值?我感觉在安装npm真的好不方便 希望作者考虑下,虽然是三个文件 光是折腾npm就挺麻烦的, 以上2个程序就是安装简单方便

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.