Merge remote-tracking branch 'remotes/origin/develop' into force-conversion-correct-formats

This commit is contained in:
Sergey Linnik
2024-11-21 17:05:25 +03:00
297 changed files with 15032 additions and 728 deletions

32
.github/workflows/artifact-go.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: Artifact Golang
on:
workflow_dispatch:
push:
branches: [master]
paths: ['web/documentserver-example/go/**']
pull_request:
branches: [master]
paths: ['web/documentserver-example/go/**']
jobs:
artifact:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build Artifact
run: |
cd ${{ github.workspace }}
cwd=$(pwd)
git submodule update --init --recursive
cd ./web/documentserver-example/go
mkdir -p ./deploy/'Go Example'
rsync -av --exclude='deploy' ./ ./deploy/'Go Example'
rm -rf ./deploy/'Go Example'/static/assets/document-formats/.git
rm -rf ./deploy/'Go Example'/static/assets/document-templates/.git
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: Go.Example
path: ${{ github.workspace }}/web/documentserver-example/go/deploy

29
.github/workflows/lint-go.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Golangci
on:
workflow_dispatch:
push:
branches: [master]
paths: ['web/documentserver-example/go/**']
pull_request:
branches: [master, develop]
paths: ['web/documentserver-example/go/**']
jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web/documentserver-example/go
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Lint Golangci
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run

View File

@ -3,10 +3,10 @@ name: Lint Java
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/java/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/java/**']
jobs:

View File

@ -3,10 +3,10 @@ name: ESLint
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/nodejs/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/nodejs/**']
env:

View File

@ -3,10 +3,10 @@ name: Laravel Pint
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/php-laravel/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/php-laravel/**']
jobs:

View File

@ -3,10 +3,10 @@ name: PHPCs
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/php/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/php/**']
jobs:

View File

@ -3,10 +3,10 @@ name: PyLint
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/python/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/python/**']
jobs:

View File

@ -3,10 +3,10 @@ name: Rubocop
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/ruby/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/ruby/**']
jobs:

View File

@ -3,10 +3,10 @@ name: Lint Spring
on:
workflow_dispatch:
push:
branches: [master, main]
branches: [master]
paths: ['web/documentserver-example/java-spring/**']
pull_request:
branches: [master, main, develop]
branches: [master, develop]
paths: ['web/documentserver-example/java-spring/**']
jobs:

View File

@ -2,7 +2,7 @@ name: Release
on:
push:
branches: [master,main]
branches: [master]
permissions:
contents: write
@ -95,6 +95,14 @@ jobs:
rsync -av --exclude='Java Spring Example' ./ ./'Java Spring Example'
rm -rf ./'Java Spring Example'/src/main/resources/assets/document-formats/.git
rm -rf ./'Java Spring Example'/src/main/resources/assets/document-templates/.git
- name: Build Go Artifact
run: |
cd ${{ github.workspace }}
cd ./web/documentserver-example/go
mkdir -p .'Go Example'
rsync -av --exclude='Go Example' ./ ./'Go Example'
rm -rf ./'Go Example'/static/assets/document-formats/.git
rm -rf ./'Go Example'/static/assets/document-templates/.git
- name: Pack Artifacts
run: |
cd ${{ github.workspace }}/web/documentserver-example/csharp-mvc
@ -115,6 +123,8 @@ jobs:
zip -r Ruby.Example.zip ./'Ruby Example'
cd ${{ github.workspace }}/web/documentserver-example/java-spring
zip -r Java.Spring.Example.zip ./'Java Spring Example'
cd ${{ github.workspace }}/web/documentserver-example/go
zip -r Go.Example.zip ./'Go Example'
- name: Create Release
uses: ncipollo/release-action@v1
id: create_release
@ -129,6 +139,7 @@ jobs:
${{ github.workspace }}/web/documentserver-example/php-laravel/PHP.Laravel.Example.zip,
${{ github.workspace }}/web/documentserver-example/python/Python.Example.zip,
${{ github.workspace }}/web/documentserver-example/ruby/Ruby.Example.zip,
${{ github.workspace }}/web/documentserver-example/java-spring/Java.Spring.Example.zip
${{ github.workspace }}/web/documentserver-example/java-spring/Java.Spring.Example.zip,
${{ github.workspace }}/web/documentserver-example/go/Go.Example.zip
"
tag: v${{ steps.info.outputs.version }}

8
.gitmodules vendored
View File

@ -36,6 +36,14 @@
path = web/documentserver-example/java-spring/src/main/resources/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/default
[submodule "web/documentserver-example/go/static/assets/document-templates"]
path = web/documentserver-example/go/static/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/default
[submodule "web/documentserver-example/go/static/assets/document-formats"]
path = web/documentserver-example/go/static/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master
[submodule "web/documentserver-example/python/assets/document-formats"]
path = web/documentserver-example/python/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats

View File

@ -82,6 +82,37 @@ License: MICROSOFT .NET LIBRARY LICENSE
License File: WebGrease.license
web/documentserver-example/go
fx - An application framework for Go that makes dependency injection easy. (https://github.com/uber-go/fx).
License: MIT
License File: fx.license
golang-jwt - A go implementation of JSON Web Tokens. (https://github.com/golang-jwt/jwt).
License: MIT
License File: golang-jwt.license
gorilla/mux - Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler. (https://github.com/gorilla/mux).
License: BSD-3-Clause License
License File: mux.license
mapstructure - Go library for decoding generic map values into native Go structures and vice versa. (https://github.com/mitchellh/mapstructure)
License: MIT
License File: mapstructure.license
schema - Package gorilla/schema fills a struct with form values. (https://github.com/gorilla/schema)
License: BSD-3-Clause License
License File: schema.license
viper - Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats. (https://github.com/spf13/viper).
License: MIT
License File: viper.license
zap - Blazing fast, structured, leveled logging in Go. (https://github.com/uber-go/zap).
License: MIT
License File: zap.license
web/documentserver-example/java
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)

View File

@ -1,9 +1,16 @@
# Change Log
- converting function on index page
- editing by default
- change reference source
- filename in editor page title
- close editor
- golang: new integration example
- golang: upload files to the server
- golang: create blank files and files with sample content
- glang: edit uploaded files in onlyoffice editor
- golang: delete files on the server
- golang: show files history
- php-laravel: new integration example
- php-laravel: upload files to the server
- php-laravel: create blank files and files with sample content

View File

@ -10,6 +10,7 @@ The package contains examples written in .Net (C# MVC), .Net (C#), Java, Java Sp
You should change `http://documentserver` to your server address in these files:
* [.Net (C# MVC)](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/csharp-mvc) - `web/documentserver-example/csharp-mvc/web.appsettings.config`
* [.Net (C#)](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/csharp) - `web/documentserver-example/csharp/settings.config`
* [Go](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/go) - `web\documentserver-example\go\config\configuration.json`
* [Java](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/java) - `web/documentserver-example/java/src/main/resources/settings.properties`
* [Java Spring](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/java-spring) - `web/documentserver-example/java-spring/src/main/resources/application.properties`
* [Node.js](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/nodejs) - `web/documentserver-example/nodejs/config/default.json`

View File

@ -1,4 +1,22 @@
.center {
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.center {
width: auto;
}

View File

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.4285 13C14.4102 13 14 13 14 13.5V15H6C5.44772 15 5 15.4477 5 16V17C5 17.5523 5.44771 18 6 18H14V19.5C14 20 14.3816 20 14.4285 20C14.6359 20 15.0099 19.9113 15.2172 19.7363L18.6207 17.0833C19.1264 16.6566 19.1264 16.3434 18.6207 15.9167L15.2172 13.2637C15.0099 13.0887 14.6359 13 14.4285 13Z" fill="#444444"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.5715 4C9.58984 4 10 4 10 4.50002V6H18C18.5523 6 19 6.44772 19 7V8C19 8.55228 18.5523 9 18 9H10V10.5C10 11 9.61841 11 9.57151 11C9.36409 11 8.99012 10.9113 8.78279 10.7363L5.37934 8.08333C4.87356 7.65662 4.87356 7.34338 5.37934 6.91667L8.78279 4.26366C8.99012 4.08874 9.36409 4 9.5715 4Z" fill="#444444"/>
</svg>

After

Width:  |  Height:  |  Size: 821 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#1E7AAA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path d="M6 15h18v1H6v-1zM6 19h18v1H6v-1zM6 23h18v1H6v-1zM6 27h18v1H6v-1z" fill="#fff"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#287CA9"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><rect x="6" y="16" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="22" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="28" width="11" height="1.5" rx=".75" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 387 B

After

Width:  |  Height:  |  Size: 527 B

View File

@ -1,5 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 3C0 1.34315 1.34315 0 3 0H23L30 7V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#9E1919"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.0062 15V16.0065H24V15H17.0062ZM17.0062 19V20.0163H24V19H17.0062ZM24 23H17.0062V24.0261H24V23ZM6 28V27.0293H24V28H6ZM7 16H14V23H7V16ZM6 15H7H14H15V16V23V24H14H7H6V23V16V15Z" fill="white"/>
<path d="M23 0L30 7H26C24.3431 7 23 5.65685 23 4V0Z" fill="black" fill-opacity="0.25"/>
</svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#E54D39"/><rect x="6" y="28" width="18" height="1.5" rx=".75" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6.75 16c-.41421 0-.75.3358-.75.75v6c0 .3624.25709.6648.59885.7348.04882.01.09937.0152.15115.0152h6.5c.4142 0 .75-.3358.75-.75v-6c0-.4142-.3358-.75-.75-.75h-6.5Zm5.75 1.5h-5V22h5v-4.5Z" fill="#fff"/><rect x="18" y="22" width="6" height="1.5" rx=".75" fill="#fff"/><rect x="18" y="16" width="6" height="1.5" rx=".75" fill="#fff"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/></svg>

Before

Width:  |  Height:  |  Size: 558 B

After

Width:  |  Height:  |  Size: 775 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#F36700"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path stroke="#fff" stroke-opacity=".95" d="M6.5 15.5h17v12h-17z"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#F36700"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><rect x="6" y="16" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="28" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="7.5" y="16" width="13.5" height="1.5" rx=".75" transform="rotate(90 7.5 16)" fill="#fff"/><rect x="24" y="16" width="13.5" height="1.5" rx=".75" transform="rotate(90 24 16)" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 366 B

After

Width:  |  Height:  |  Size: 658 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#D0D5DA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 23c-.27614 0-.5.2239-.5.5v4c0 .2761.22386.5.5.5h15c.2761 0 .5-.2239.5-.5v-4c0-.2761-.2239-.5-.5-.5h-2c-.2761 0-.5-.2239-.5-.5s.2239-.5.5-.5h2c.8284 0 1.5.6716 1.5 1.5v4c0 .8284-.6716 1.5-1.5 1.5h-15c-.82843 0-1.5-.6716-1.5-1.5v-4c0-.8284.67157-1.5 1.5-1.5h2c.27614 0 .5.2239.5.5s-.22386.5-.5.5h-2z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 20.0001L15 14l-5 6.0001h3v4c0 .5523.4477 1 1 1h2c.5523 0 1-.4477 1-1v-4h3z" fill="#646464"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3Z" fill="#D0D5DA"/><path d="m23 0 7 7h-4c-1.6569 0-3-1.34315-3-3V0Z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 23c-.27614 0-.5.2239-.5.5v4c0 .2761.22386.5.5.5h15c.2761 0 .5-.2239.5-.5v-4c0-.2761-.2239-.5-.5-.5h-2c-.2761 0-.5-.2239-.5-.5s.2239-.5.5-.5h2c.8284 0 1.5.6716 1.5 1.5v4c0 .8284-.6716 1.5-1.5 1.5h-15c-.82843 0-1.5-.6716-1.5-1.5v-4c0-.8284.67157-1.5 1.5-1.5h2c.27614 0 .5.2239.5.5s-.22386.5-.5.5h-2Z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 20.0001 15 14l-5 6.0001h3v4c0 .5522.4477 1 1 1h2c.5523 0 1-.4478 1-1v-4h3Z" fill="#646464"/></svg>

Before

Width:  |  Height:  |  Size: 797 B

After

Width:  |  Height:  |  Size: 797 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#6AAA1E"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6 15h18v13H7.00001v-1H12v-3H7v4H6V15zm7 12h4v-3h-4v3zm5 0h5v-3h-5v3zm5-7v3h-5v-3h5zm-6 0v3h-4v-3h4zm-5 0v3H7v-3h5zm11-1v-3h-5v3h5zm-10-3h4v3h-4v-3zm-1 3v-3H7v3h5z" fill="#fff" fill-opacity=".95"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#3AA133"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6.75 16c-.41421 0-.75.3358-.75.75v11.5c0 .0877.01504.1718.04268.25-.02764.0782-.04268.1623-.04268.25 0 .4142.33579.75.75.75h16.5c.4142 0 .75-.3358.75-.75 0-.0877-.015-.1718-.0427-.25.0277-.0782.0427-.1623.0427-.25v-11.5c0-.4142-.3358-.75-.75-.75H6.75Zm5.75 1.5h-5V22h5v-4.5ZM14 22v-4.5h8.5V22H14Zm-1.5 1.5h-5V28h5v-4.5ZM14 28v-4.5h8.5V28H14Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 738 B

View File

@ -1,12 +1 @@
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.84616 1H10.8462L14.8462 5V15H2.84616V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.8462 5L10.8462 1H2.84616V15H14.8462V5ZM10.8462 0L15.8462 5V16H1.84616V0H10.8462Z" fill="#BFBFBF"/>
<rect x="3.84616" y="10" width="10" height="4" fill="#3779A6"/>
<path d="M3.84616 4H4.84616V5H3.84616V4Z" fill="#BFBFBF"/>
<path d="M3.84616 6H4.84616V7H3.84616V6Z" fill="#BFBFBF"/>
<path d="M4.84616 8H3.84616V9H4.84616V8Z" fill="#BFBFBF"/>
<path d="M12.8462 8H5.84616V9H12.8462V8Z" fill="#BFBFBF"/>
<path d="M7.84616 6H5.84616V7H7.84616V6Z" fill="#BFBFBF"/>
<path d="M12.8462 4H5.84616V5H12.8462V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9.84616 1H10.8462V4H14.8462L15.8462 5H9.84616V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 7H5v1h6V7ZM5 9h4v1H5V9Zm0 2h4v1H5v-1Z" fill="#287CA9"/><path d="M10 9h5v5h-5V9Z" fill="#287CA9"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h1v1.2163h1V10h1v3h-3v-3Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 617 B

View File

@ -1 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2 1h8l4 4v10H2V1z" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M14 5l-4-4H2v14h12V5zm-4-5l5 5v11H1V0h9z" fill="#BFBFBF"/><path fill="#9E1919" d="M3 10h10v4H3z"/><path d="M7 7V2H3v5h4zM8 3V2h2v1H8zM8 5V4h5v1H8zM13 6H8v1h5V6zM13 8H3v1h10V8z" fill="#BFBFBF"/><path opacity=".3" d="M9 1h1v3h4l1 1H9V1z" fill="#333"/></svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path d="M10 9h5v5h-5V9Z" fill="#E52910"/><path fill="#fff" d="M11 12h1v1h-1zM12 10h1v1h-1zM12 11h1v1h-1zM13 11h1v1h-1z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 7H5v1h6V7ZM5 9h4v1H5V9Zm0 2h4v1H5v-1Z" fill="#E52910"/></svg>

Before

Width:  |  Height:  |  Size: 441 B

After

Width:  |  Height:  |  Size: 602 B

View File

@ -1,12 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 1H10L14 5V15H2V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14 5L10 1H2V15H14V5ZM10 0L15 5V16H1V0H10Z" fill="#BFBFBF"/>
<rect x="3" y="10" width="10" height="4" fill="#F36700"/>
<path d="M3 4H4V5H3V4Z" fill="#BFBFBF"/>
<path d="M3 6H4V7H3V6Z" fill="#BFBFBF"/>
<path d="M4 8H3V9H4V8Z" fill="#BFBFBF"/>
<path d="M12 8H5V9H12V8Z" fill="#BFBFBF"/>
<path d="M7 6H5V7H7V6Z" fill="#BFBFBF"/>
<path d="M12 4H5V5H12V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9 1H10V4H14L15 5H9V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path d="M5.25 9c-.13807 0-.25161-.11236-.2344-.24935.02224-.17697.0681-.35054.13664-.51602.10051-.24265.24783-.46313.43355-.64884.18571-.18572.40619-.33304.64884-.43355.16548-.06854.33905-.1144.51602-.13664C6.88764 6.99839 7 7.11193 7 7.25v1.5c0 .13807-.11193.25-.25.25h-1.5Z" fill="#ED771C"/><path d="M5.25 10c-.13807 0-.25108.1121-.23959.2497.0422.5053.21197.9932.49518 1.417.32965.4934.79818.8779 1.34636 1.1049.54818.2271 1.15138.2865 1.73332.1708.58194-.1158 1.11649-.4015 1.53603-.8211.4196-.4195.7053-.9541.8211-1.536.1157-.582.0563-1.18517-.1708-1.73335-.227-.54818-.6115-1.01671-1.10489-1.34636-.42386-.28321-.91169-.45298-1.41699-.49518C8.11213 6.99892 8 7.11193 8 7.25v2.5c0 .13807-.11193.25-.25.25h-2.5Z" fill="#F8C9A4"/><path d="M10 9h5v5h-5V9Z" fill="#ED771C"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h2.7305v2H12v1h-1v-3Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,12 +1 @@
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.84592 1H10.8459L14.8459 5V15H2.84592V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.8459 5L10.8459 1H2.84592V15H14.8459V5ZM10.8459 0L15.8459 5V16H1.84592V0H10.8459Z" fill="#BFBFBF"/>
<rect x="3.84592" y="10" width="10" height="4" fill="#78A73B"/>
<path d="M3.84592 4H4.84592V5H3.84592V4Z" fill="#BFBFBF"/>
<path d="M3.84592 6H4.84592V7H3.84592V6Z" fill="#BFBFBF"/>
<path d="M4.84592 8H3.84592V9H4.84592V8Z" fill="#BFBFBF"/>
<path d="M12.8459 8H5.84592V9H12.8459V8Z" fill="#BFBFBF"/>
<path d="M7.84592 6H5.84592V7H7.84592V6Z" fill="#BFBFBF"/>
<path d="M12.8459 4H5.84592V5H12.8459V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9.84592 1H10.8459V4H14.8459L15.8459 5H9.84592V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path fill-rule="evenodd" clip-rule="evenodd" d="M9 7h3v1H9V7ZM8 9H5v1h3V9Zm0 2H5v1h3v-1Zm0-4H5v1h3V7Z" fill="#3AA133"/><path d="M10 9h5v5h-5V9Z" fill="#3AA133"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h1v1h-1v-1Zm2 1h-1v1h-1v1h1v-1h1v1h1v-1h-1v-1Zm0 0v-1h1v1h-1Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 665 B

View File

@ -42,10 +42,14 @@
}
.tableHeaderCellViewers {
width: 29%;
width: 18%;
text-align: right;
}
.tableHeaderCellAction {
width: 23%;
}
.tableHeaderCellDownload {
width: 21%;
padding-right: 18px;
@ -220,7 +224,7 @@
}
.tableHeaderCellFileName {
width: 16%;
width: 9%;
}
.tableHeaderCellEditors {
@ -229,7 +233,12 @@
.tableHeaderCellViewers {
text-align: right;
width: 37%;
width: 9%;
}
.tableHeaderCellAction{
width: 11%;
padding-right: 82px;
}
.tableHeaderCellDownload {
@ -244,19 +253,24 @@
}
.tableHeaderCellEditors {
width: 26%;
width: 15%;
text-align: left;
}
.tableHeaderCellFileName {
width: 17%;
width: 28%;
}
.tableHeaderCellViewers {
width: 27%;
width: 6%;
text-align: right;
}
.tableHeaderCellAction{
width: 18%;
padding-right: 54px;
}
.tableHeaderCellDownload {
padding-right: 18px;
width: 20%;
@ -277,12 +291,17 @@
.tableRow td:first-child {
flex-grow: 0;
width: 15%;
width: 25%;
margin-right: auto;
}
.contentCells-icon {
width: 3%;
}
.firstContentCellViewers {
margin-left: 0;
}
}
@media (max-width: 890px) and (min-width: 769px ) {
@ -290,7 +309,7 @@
width: 20%;
}
.contentCells-shift {
padding-right: 28px;
padding-right: 27px;
}
.main-panel {
@ -323,11 +342,16 @@
.tableHeaderCellEditors {
text-align: left;
width: 31%;
width: 1%;
}
.tableHeaderCellViewers {
width: 18%;
width: 19%;
}
.tableHeaderCellAction {
width: 19%;
padding-right: 45px;
}
}
@ -429,8 +453,8 @@
.downloadContentCellShift {
max-width: 7%;
margin-right: -11px;
margin-left: auto;
margin-right: 24px;
margin-left: 0;
}
.contentCells-icon {
@ -438,13 +462,13 @@
}
.tableRow td:last-child {
width: 12%;
padding-right: 40px;
width: 7%;
padding-right: 0px;
border: none;
}
.contentCells-shift {
padding-right: 35px;
padding-right: 0px;
}
.downloadContentCellShift:after {
@ -530,6 +554,15 @@
height: 56px;
margin-bottom: 24px !important;
}
.button.hoar{
width: 18%;
height: 27px;
margin-bottom: 7px !important;
}
.button.converting{
width: 126px;
margin-top: 0;
}
}
@media (max-width: 560px) and (min-width: 510px) {
@ -538,7 +571,7 @@
}
.downloadContentCellShift {
padding-right: 45px;
padding-right: 16px;
max-width: 4%;
}
}
@ -558,7 +591,7 @@
.downloadContentCellShift {
max-width: 6%;
padding-right: 37px;
padding-right: 6px;
}
.firstContentCellShift {
@ -584,12 +617,12 @@
.downloadContentCellShift {
max-width: 3%;
padding-right: 37px;
padding-right: 0px;
padding-left: 0;
}
.firstContentCellShift {
margin-left: 1px;
margin-left: 2px;
flex-basis: 14%;
}
@ -619,7 +652,7 @@
.downloadContentCellShift {
max-width: 4%;
margin-right: -18px;
margin-right: 18px;
margin-left: -1px;
}
@ -628,7 +661,7 @@
}
.contentCells-icon{
width: 10%;
width: 12%;
}
footer table td {
margin: 0;

View File

@ -238,6 +238,52 @@ label .checkbox {
color: #FF6F3D;
}
.button.converting {
margin-top: -20px;
padding: 16px 16px;
}
.button.converting.wide {
padding: 16px 29px;
}
.button.hoar {
background: #EFEFEF;
border: 1px solid #EFEFEF;
margin-right: 7px;
margin-bottom: 7px;
width: 13%;
padding-left: 0;
padding-right: 0;
font-size: 11px;
}
.button.hoar.disable {
opacity: 30%;
cursor: default;
}
.button.hoar:not(.disable):hover {
background: #FF6F3D;
border: 1px solid #FF6F3D;
color: #FFFFFF;
}
.button.hoar.orange {
background: #FF6F3D;
border: 1px solid #FF6F3D;
color: #FFFFFF;
cursor: default;
}
.button.hoar.orange.disable {
background: #444444;
border: 1px solid #444444;
color: #FFFFFF;
cursor: default;
opacity: 100%;
}
.button.file-type {
font-size: 11px;
color: #FFFFFF;
@ -380,6 +426,32 @@ label .checkbox {
display: none;
}
#convertingProgress {
color: #333333;
display: none;
font-size: 12px;
margin: 30px 35px;
}
#convertingProgress .convertFileName{
background-position: left center;
background-repeat: no-repeat;
display: block;
font-size: 14px;
line-height: 160%;
overflow: hidden;
padding-left: 28px;
margin-bottom: 16px;
text-overflow: ellipsis;
white-space: nowrap;
}
#convertingProgress .describeUpload {
line-height: 150%;
letter-spacing: -0.02em;
padding: 16px 0;
}
.error-message {
background: url("images/error.svg") no-repeat scroll 4px 10px;
color: #CB0000;
@ -401,6 +473,10 @@ label .checkbox {
padding-left: 35px;
}
.waiting {
opacity: 30%;
}
.current {
background-image: url("images/loader16.gif");
}
@ -413,6 +489,12 @@ label .checkbox {
background-image: url("images/notdone.svg");
}
.convertPercent {
color: #FF6F3D;
font-weight: 700;
display: inline;
}
.step-descr {
display: block;
margin-left: 35px;
@ -420,6 +502,10 @@ label .checkbox {
line-height: 188%;
}
.step-descr.disable {
display: none;
}
.progress-descr {
letter-spacing: -0.02em;
line-height: 150%;
@ -521,21 +607,25 @@ footer table tr td:first-child {
white-space: nowrap;
}
.convertFileName.word,
.stored-edit.word,
.uploadFileName.word {
background-image: url("images/icon_docx.svg");
}
.convertFileName.cell,
.stored-edit.cell,
.uploadFileName.cell {
background-image: url("images/icon_xlsx.svg");
}
.convertFileName.slide,
.stored-edit.slide,
.uploadFileName.slide {
background-image: url("images/icon_pptx.svg");
}
.convertFileName.pdf,
.stored-edit.pdf,
.uploadFileName.pdf {
background-image: url("images/icon_pdf.svg");
@ -592,6 +682,11 @@ footer table tr td:first-child {
visibility: hidden;
}
.convertTable {
margin-top: 10px;
margin-left: 35px;
}
.tableRow {
background: transparent;
-moz-transition: all 0.2s ease-in-out;
@ -638,6 +733,12 @@ footer table tr td:first-child {
width: 11%;
}
.tableHeaderCellAction{
width: 13%;
text-align: right;
padding-right: 88px;
}
.tableHeaderCellDownload {
width: 13%;
text-align: right;
@ -662,7 +763,7 @@ footer table tr td:first-child {
}
.contentCells-shift {
padding-right: 44px;
padding-right: 43px;
}
.contentCells-icon {
@ -726,7 +827,7 @@ footer table tr td:first-child {
width: 100%;
}
.icon-delete {
.icon-action {
cursor: pointer;
}
@ -805,6 +906,13 @@ html {
position: relative;
}
.typeButtonsRow {
width: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
position: relative;
}
.tableRow td:first-child {
display: flex;
@ -813,11 +921,11 @@ html {
}
.tableHeaderCellFileName {
width: 30%;
width: 20%;
}
.tableHeaderCellEditors {
width: 28%;
width: 20%;
}
.tableHeaderCellViewers {

View File

@ -31,6 +31,7 @@ namespace OnlineEditorsExampleMVC.Models
{
public enum FileType
{
Null,
Word,
Cell,
Slide,
@ -47,7 +48,7 @@ namespace OnlineEditorsExampleMVC.Models
if (FormatManager.SpreadsheetExtensions().Contains(ext)) return FileType.Cell; // cell type for spreadsheet extensions
if (FormatManager.PresentationExtensions().Contains(ext)) return FileType.Slide; // slide type for presentation extensions
return FileType.Word; // the default type is word
return FileType.Null; // the default type is word
}
}

View File

@ -1,3 +1,21 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
function deleteFile(event) {
let filename = event.currentTarget.getAttribute("data");
filename = encodeURIComponent(filename);

View File

@ -304,6 +304,134 @@ if (typeof jQuery != "undefined") {
jq("#embeddedView").attr("src", url);
});
jq(document).on("click", "#beginEditConverted:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').attr("data"));
var url = UrlEditor + "?fileName=" + fileId;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginViewConverted:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').attr("data"));
var url = UrlEditor + "?editorsMode=view&fileName=" + fileId;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#downloadConverted:not(.disable)", function () {
var fileId = jq('#hiddenFileName').attr("data");
if (jq("#downloadConverted").attr("data") == "fromConverter") window.location.assign(fileId);
else window.open("webeditor.ashx?type=download&fileName=" + encodeURIComponent(fileId), "_blank");
});
jq(document).on("click", ".convert-file", function () {
const currentElement = jq(this);
var fileName = currentElement.attr("data");
var type = currentElement.attr("data-type");
jq.blockUI({
theme: true,
title: "Converting file" + "<div class=\"dialog-close\"></div>",
message: jq("#convertingProgress"),
overlayCSS: { "background-color": "#aaa" },
themedCSS: { width: "539px", top: "20%", left: "50%", marginLeft: "-269px" }
});
jq("#convertFileName").text(decodeURIComponent(fileName));
jq("#convertFileName").removeClass("word slide cell");
jq("#convertFileName").addClass(type);
jq("#convTypes").empty();
let format = formatManager.findByExtension(fileName.split('.').pop());
if (format) {
format.convert.forEach(ext => {
jq("#convTypes").append(jq(`<td name="convertingTypeButton" id="wordTo${ext}" class="button hoar" data="${ext}">${ext}</td>`));
});
}
jq("#hiddenFileName").val(fileName);
jq("#convertStep1").addClass("done");
jq("#convertStep2").addClass("waiting");
});
jq(document).on("click", "td[name='convertingTypeButton']:not(.disable, .orange)", function () {
const currentElement = jq(this);
let id = currentElement[0].id;
let fileExt = jq(`#${id}`).attr("data");
jq(`#${id}`).addClass("orange");
jq("td[name='convertingTypeButton']").addClass("disable");
jq("#convertStep2").removeClass("waiting").removeClass("done").addClass("current");
jq("#convertStep2").text('2. File conversion');
jq("#convert-descr").removeClass("disable");
jq("#convertPercent").text("0 %");
jq("#hiddenFileName").attr("placeholder",fileExt);
jq("#downloadConverted").addClass("disable");
jq("#beginEditConverted").addClass("disable");
jq("#beginViewConverted").addClass("disable");
mustReload = true;
convertFile();
});
function convertFile (filePass) {
let fileName = decodeURIComponent(jq("#hiddenFileName").val());
let fileExt = jq("#hiddenFileName").attr("placeholder");
filePass = filePass ? filePass : null;
if (timer != null) {
clearTimeout(timer);
}
timer = setTimeout(function () {
jq.ajax({
async: true,
contentType: "text/xml",
type: "post",
dataType: "json",
data: JSON.stringify({filename: fileName, filePass: filePass, lang: language, fileExt: fileExt, keepOriginal: true}),
url: UrlConverter,
complete: function (data) {
try {
var response = jq.parseJSON(data.responseText);
} catch (e) {
response = { error: e };
}
if (!response.filename && !response.step && response.error) {
jq("#convertStep2").removeClass("current").addClass("error");
jq("#convertStep2").text(`2. File conversion to ${fileExt}`);
jq("#convert-error").removeClass("hidden");
jq("#convert-error").text(`${response.error}`);
jq("td[name='convertingTypeButton']").removeClass("disable orange");
return;
}
if (response.step != undefined && response.step != 100) {
jq("#convertPercent").text(`${response.step} %`);
convertFile();
} else {
jq("#convertPercent").text(`${response.step} %`);
jq("#convertStep2").removeClass("current").addClass("done");
jq("#convertStep2").text(`2. File conversion to ${fileExt}`);
jq("#downloadConverted").removeClass("disable");
if (response.error !== "FileTypeIsNotSupported") {
jq("#hiddenFileName").attr("data",response.filename);
jq("#beginEditConverted").removeClass("disable");
jq("#beginViewConverted").removeClass("disable");
jq("#downloadConverted").attr("data","fromStorage");
} else {
let newFilename = fileName.split('.').slice(0,-1).join('.')
jq("#hiddenFileName").attr("data",response.filename.split("&filename=download").join(`&filename=${newFilename}`));
jq("#downloadConverted").attr("data","fromConverter");
}
jq("td[name='convertingTypeButton']").removeClass("disable orange");
}
}
});
}, 1000);
}
jq(document).on("click", "#cancelEdit, .dialog-close", function () {
jq('#hiddenFileName').val("");
jq("#embeddedView").attr("src", "");

View File

@ -192,8 +192,7 @@
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
<td class="tableHeaderCell tableHeaderCellEditors contentCells-shift">Editors</td>
<td class="tableHeaderCell tableHeaderCellViewers">Viewers</td>
<td class="tableHeaderCell tableHeaderCellDownload">Download</td>
<td class="tableHeaderCell tableHeaderCellRemove">Remove</td>
<td class="tableHeaderCell tableHeaderCellAction">Action</td>
</tr>
</thead>
</table>
@ -301,14 +300,22 @@
<img src="content/images/embeded.svg" alt="Open in embedded mode" title="Open in embedded mode"/>
</a>
</td>
<td class="contentCells contentCells-icon contentCells-shift downloadContentCellShift">
<% if (docType != null ) { %>
<td class="contentCells contentCells-icon">
<a class="convert-file" data="<%= storedFile.Name %>" data-type="<%= docType %>">
<img class="icon-action" src="content/images/convert.svg" alt="Convert" title="Convert" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-icon downloadContentCellShift"></td>
<% } %>
<td class="contentCells contentCells-icon downloadContentCellShift">
<a href="webeditor.ashx?type=download&fileName=<%= HttpUtility.UrlEncode(storedFile.Name) %>">
<img class="icon-download" src="content/images/download.svg" alt="Download" title="Download" />
</a>
</td>
<td class="contentCells contentCells-icon contentCells-shift">
<a class="delete-file" data-filename="<%= storedFile.Name %>">
<img class="icon-delete" src="content/images/delete.svg" alt="Delete" title="Delete" />
<img class="icon-action" src="content/images/delete.svg" alt="Delete" title="Delete" />
</a>
</td>
</tr>
@ -377,6 +384,32 @@
</div>
</div>
<div id="convertingProgress">
<div id="convertingSteps">
<span id="convertFileName" class="convertFileName"></span>
<span id="convertStep1" class="step">1. Select a format file to convert</span>
<span class="step-descr">The converting speed depends on file size and additional elements it contains.</span>
<table cellspacing="0" cellpadding="0" width="100%" class="convertTable">
<tbody>
<tr class="typeButtonsRow" id="convTypes"></tr>
</tbody>
</table>
<br />
<span id="convertStep2" class="step">2. File conversion</span>
<span class="step-descr disable" id="convert-descr">The file is converted <div class="convertPercent" id="convertPercent">0 %</div></span>
<span class="step-error hidden" id="convert-error"></span>
<div class="describeUpload">Note the speed of all operations depends on your connection quality and server location.</div>
<input type="hidden" name="hiddenFileName" id="hiddenFileName" />
</div>
<br />
<div class="buttonsMobile">
<div id="downloadConverted" class="button converting orange disable">DOWNLOAD</div>
<div id="beginViewConverted" class="button converting wide gray disable">VIEW</div>
<div id="beginEditConverted" class="button converting wide gray disable">EDIT</div>
<div id="cancelEdit" class="button converting gray">CANCEL</div>
</div>
</div>
<span id="loadScripts" data-docs="<%= WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.preloader"] %>"></span>
<footer>

View File

@ -254,8 +254,15 @@ namespace OnlineEditorsExampleMVC
conversionExtension = fileExt.ToString();
}
object keepOriginal;
bool removeOriginal = true;
if (body.TryGetValue("keepOriginal", out keepOriginal) && !String.IsNullOrEmpty(keepOriginal.ToString()))
{
removeOriginal = keepOriginal.ToString().ToLower() != "true";
}
// check if the file with such an extension can be converted
if (DocManagerHelper.ConvertExts.Contains("." + extension))
if (DocManagerHelper.ConvertExts.Contains("." + extension) || conversionExtension != "ooxml")
{
// generate document key
var key = ServiceConverter.GenerateRevisionId(fileUri);
@ -278,9 +285,14 @@ namespace OnlineEditorsExampleMVC
}
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
var newFileType = newFileData["fileType"];
if (!FormatManager.All().Any(f => f.Name == newFileType && f.Type != FileUtility.FileType.Null))
{
context.Response.Write("{\"step\": \"" + result + "\", \"filename\": \"" + newFileUri + "\", \"error\": \"FileTypeIsNotSupported\"}");
return;
}
// get a file name of an internal file extension with an index if the file with such a name already exists
var correctName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + newFileType);
var correctName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "." + newFileType);
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
@ -302,11 +314,14 @@ namespace OnlineEditorsExampleMVC
}
}
Remove(fileName); // remove the original file and its history if it exists
if (removeOriginal) Remove(fileName); // remove the original file and its history if it exists
fileName = correctName; // create meta information about the converted file with user id and name specified
var id = context.Request.Cookies.GetOrDefault("uid", null);
var user = Users.getUser(id);
DocManagerHelper.CreateMeta(fileName, user.id, user.name);
context.Response.Write("{ \"filename\" : \"" + fileName + "\", \"step\": \"" + result + "\" }");
return;
}
var documentType = FileUtility.GetFileType(fileName).ToString().ToLower();

View File

@ -1,4 +1,22 @@
.center {
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
.center {
width: auto;
}

View File

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.4285 13C14.4102 13 14 13 14 13.5V15H6C5.44772 15 5 15.4477 5 16V17C5 17.5523 5.44771 18 6 18H14V19.5C14 20 14.3816 20 14.4285 20C14.6359 20 15.0099 19.9113 15.2172 19.7363L18.6207 17.0833C19.1264 16.6566 19.1264 16.3434 18.6207 15.9167L15.2172 13.2637C15.0099 13.0887 14.6359 13 14.4285 13Z" fill="#444444"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.5715 4C9.58984 4 10 4 10 4.50002V6H18C18.5523 6 19 6.44772 19 7V8C19 8.55228 18.5523 9 18 9H10V10.5C10 11 9.61841 11 9.57151 11C9.36409 11 8.99012 10.9113 8.78279 10.7363L5.37934 8.08333C4.87356 7.65662 4.87356 7.34338 5.37934 6.91667L8.78279 4.26366C8.99012 4.08874 9.36409 4 9.5715 4Z" fill="#444444"/>
</svg>

After

Width:  |  Height:  |  Size: 821 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#1E7AAA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path d="M6 15h18v1H6v-1zM6 19h18v1H6v-1zM6 23h18v1H6v-1zM6 27h18v1H6v-1z" fill="#fff"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#287CA9"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><rect x="6" y="16" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="22" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="28" width="11" height="1.5" rx=".75" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 387 B

After

Width:  |  Height:  |  Size: 527 B

View File

@ -1,5 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 3C0 1.34315 1.34315 0 3 0H23L30 7V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#9E1919"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.0062 15V16.0065H24V15H17.0062ZM17.0062 19V20.0163H24V19H17.0062ZM24 23H17.0062V24.0261H24V23ZM6 28V27.0293H24V28H6ZM7 16H14V23H7V16ZM6 15H7H14H15V16V23V24H14H7H6V23V16V15Z" fill="white"/>
<path d="M23 0L30 7H26C24.3431 7 23 5.65685 23 4V0Z" fill="black" fill-opacity="0.25"/>
</svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#E54D39"/><rect x="6" y="28" width="18" height="1.5" rx=".75" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6.75 16c-.41421 0-.75.3358-.75.75v6c0 .3624.25709.6648.59885.7348.04882.01.09937.0152.15115.0152h6.5c.4142 0 .75-.3358.75-.75v-6c0-.4142-.3358-.75-.75-.75h-6.5Zm5.75 1.5h-5V22h5v-4.5Z" fill="#fff"/><rect x="18" y="22" width="6" height="1.5" rx=".75" fill="#fff"/><rect x="18" y="16" width="6" height="1.5" rx=".75" fill="#fff"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/></svg>

Before

Width:  |  Height:  |  Size: 558 B

After

Width:  |  Height:  |  Size: 775 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#F36700"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path stroke="#fff" stroke-opacity=".95" d="M6.5 15.5h17v12h-17z"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#F36700"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><rect x="6" y="16" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="6" y="28" width="18" height="1.5" rx=".75" fill="#fff"/><rect x="7.5" y="16" width="13.5" height="1.5" rx=".75" transform="rotate(90 7.5 16)" fill="#fff"/><rect x="24" y="16" width="13.5" height="1.5" rx=".75" transform="rotate(90 24 16)" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 366 B

After

Width:  |  Height:  |  Size: 658 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#D0D5DA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 23c-.27614 0-.5.2239-.5.5v4c0 .2761.22386.5.5.5h15c.2761 0 .5-.2239.5-.5v-4c0-.2761-.2239-.5-.5-.5h-2c-.2761 0-.5-.2239-.5-.5s.2239-.5.5-.5h2c.8284 0 1.5.6716 1.5 1.5v4c0 .8284-.6716 1.5-1.5 1.5h-15c-.82843 0-1.5-.6716-1.5-1.5v-4c0-.8284.67157-1.5 1.5-1.5h2c.27614 0 .5.2239.5.5s-.22386.5-.5.5h-2z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 20.0001L15 14l-5 6.0001h3v4c0 .5523.4477 1 1 1h2c.5523 0 1-.4477 1-1v-4h3z" fill="#646464"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3Z" fill="#D0D5DA"/><path d="m23 0 7 7h-4c-1.6569 0-3-1.34315-3-3V0Z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 23c-.27614 0-.5.2239-.5.5v4c0 .2761.22386.5.5.5h15c.2761 0 .5-.2239.5-.5v-4c0-.2761-.2239-.5-.5-.5h-2c-.2761 0-.5-.2239-.5-.5s.2239-.5.5-.5h2c.8284 0 1.5.6716 1.5 1.5v4c0 .8284-.6716 1.5-1.5 1.5h-15c-.82843 0-1.5-.6716-1.5-1.5v-4c0-.8284.67157-1.5 1.5-1.5h2c.27614 0 .5.2239.5.5s-.22386.5-.5.5h-2Z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 20.0001 15 14l-5 6.0001h3v4c0 .5522.4477 1 1 1h2c.5523 0 1-.4478 1-1v-4h3Z" fill="#646464"/></svg>

Before

Width:  |  Height:  |  Size: 797 B

After

Width:  |  Height:  |  Size: 797 B

View File

@ -1 +1 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#6AAA1E"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6 15h18v13H7.00001v-1H12v-3H7v4H6V15zm7 12h4v-3h-4v3zm5 0h5v-3h-5v3zm5-7v3h-5v-3h5zm-6 0v3h-4v-3h4zm-5 0v3H7v-3h5zm11-1v-3h-5v3h5zm-10-3h4v3h-4v-3zm-1 3v-3H7v3h5z" fill="#fff" fill-opacity=".95"/></svg>
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 2.5C0 1.11929 1.11929 0 2.5 0H21l9 9v28.5c0 1.3807-1.1193 2.5-2.5 2.5h-25C1.11929 40 0 38.8807 0 37.5v-35Z" fill="#3AA133"/><path d="m21 0 9 9h-7.3636C21.7326 9 21 8.26737 21 7.36364V0Z" fill="#000" fill-opacity=".25"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6.75 16c-.41421 0-.75.3358-.75.75v11.5c0 .0877.01504.1718.04268.25-.02764.0782-.04268.1623-.04268.25 0 .4142.33579.75.75.75h16.5c.4142 0 .75-.3358.75-.75 0-.0877-.015-.1718-.0427-.25.0277-.0782.0427-.1623.0427-.25v-11.5c0-.4142-.3358-.75-.75-.75H6.75Zm5.75 1.5h-5V22h5v-4.5ZM14 22v-4.5h8.5V22H14Zm-1.5 1.5h-5V28h5v-4.5ZM14 28v-4.5h8.5V28H14Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 738 B

View File

@ -1,12 +1 @@
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.84616 1H10.8462L14.8462 5V15H2.84616V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.8462 5L10.8462 1H2.84616V15H14.8462V5ZM10.8462 0L15.8462 5V16H1.84616V0H10.8462Z" fill="#BFBFBF"/>
<rect x="3.84616" y="10" width="10" height="4" fill="#3779A6"/>
<path d="M3.84616 4H4.84616V5H3.84616V4Z" fill="#BFBFBF"/>
<path d="M3.84616 6H4.84616V7H3.84616V6Z" fill="#BFBFBF"/>
<path d="M4.84616 8H3.84616V9H4.84616V8Z" fill="#BFBFBF"/>
<path d="M12.8462 8H5.84616V9H12.8462V8Z" fill="#BFBFBF"/>
<path d="M7.84616 6H5.84616V7H7.84616V6Z" fill="#BFBFBF"/>
<path d="M12.8462 4H5.84616V5H12.8462V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9.84616 1H10.8462V4H14.8462L15.8462 5H9.84616V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 7H5v1h6V7ZM5 9h4v1H5V9Zm0 2h4v1H5v-1Z" fill="#287CA9"/><path d="M10 9h5v5h-5V9Z" fill="#287CA9"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h1v1.2163h1V10h1v3h-3v-3Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 617 B

View File

@ -1 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2 1h8l4 4v10H2V1z" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M14 5l-4-4H2v14h12V5zm-4-5l5 5v11H1V0h9z" fill="#BFBFBF"/><path fill="#9E1919" d="M3 10h10v4H3z"/><path d="M7 7V2H3v5h4zM8 3V2h2v1H8zM8 5V4h5v1H8zM13 6H8v1h5V6zM13 8H3v1h10V8z" fill="#BFBFBF"/><path opacity=".3" d="M9 1h1v3h4l1 1H9V1z" fill="#333"/></svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path d="M10 9h5v5h-5V9Z" fill="#E52910"/><path fill="#fff" d="M11 12h1v1h-1zM12 10h1v1h-1zM12 11h1v1h-1zM13 11h1v1h-1z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 7H5v1h6V7ZM5 9h4v1H5V9Zm0 2h4v1H5v-1Z" fill="#E52910"/></svg>

Before

Width:  |  Height:  |  Size: 441 B

After

Width:  |  Height:  |  Size: 602 B

View File

@ -1,12 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 1H10L14 5V15H2V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14 5L10 1H2V15H14V5ZM10 0L15 5V16H1V0H10Z" fill="#BFBFBF"/>
<rect x="3" y="10" width="10" height="4" fill="#F36700"/>
<path d="M3 4H4V5H3V4Z" fill="#BFBFBF"/>
<path d="M3 6H4V7H3V6Z" fill="#BFBFBF"/>
<path d="M4 8H3V9H4V8Z" fill="#BFBFBF"/>
<path d="M12 8H5V9H12V8Z" fill="#BFBFBF"/>
<path d="M7 6H5V7H7V6Z" fill="#BFBFBF"/>
<path d="M12 4H5V5H12V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9 1H10V4H14L15 5H9V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path d="M5.25 9c-.13807 0-.25161-.11236-.2344-.24935.02224-.17697.0681-.35054.13664-.51602.10051-.24265.24783-.46313.43355-.64884.18571-.18572.40619-.33304.64884-.43355.16548-.06854.33905-.1144.51602-.13664C6.88764 6.99839 7 7.11193 7 7.25v1.5c0 .13807-.11193.25-.25.25h-1.5Z" fill="#ED771C"/><path d="M5.25 10c-.13807 0-.25108.1121-.23959.2497.0422.5053.21197.9932.49518 1.417.32965.4934.79818.8779 1.34636 1.1049.54818.2271 1.15138.2865 1.73332.1708.58194-.1158 1.11649-.4015 1.53603-.8211.4196-.4195.7053-.9541.8211-1.536.1157-.582.0563-1.18517-.1708-1.73335-.227-.54818-.6115-1.01671-1.10489-1.34636-.42386-.28321-.91169-.45298-1.41699-.49518C8.11213 6.99892 8 7.11193 8 7.25v2.5c0 .13807-.11193.25-.25.25h-2.5Z" fill="#F8C9A4"/><path d="M10 9h5v5h-5V9Z" fill="#ED771C"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h2.7305v2H12v1h-1v-3Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,12 +1 @@
<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.84592 1H10.8459L14.8459 5V15H2.84592V1Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.8459 5L10.8459 1H2.84592V15H14.8459V5ZM10.8459 0L15.8459 5V16H1.84592V0H10.8459Z" fill="#BFBFBF"/>
<rect x="3.84592" y="10" width="10" height="4" fill="#78A73B"/>
<path d="M3.84592 4H4.84592V5H3.84592V4Z" fill="#BFBFBF"/>
<path d="M3.84592 6H4.84592V7H3.84592V6Z" fill="#BFBFBF"/>
<path d="M4.84592 8H3.84592V9H4.84592V8Z" fill="#BFBFBF"/>
<path d="M12.8459 8H5.84592V9H12.8459V8Z" fill="#BFBFBF"/>
<path d="M7.84592 6H5.84592V7H7.84592V6Z" fill="#BFBFBF"/>
<path d="M12.8459 4H5.84592V5H12.8459V4Z" fill="#BFBFBF"/>
<path opacity="0.3" d="M9.84592 1H10.8459V4H14.8459L15.8459 5H9.84592V1Z" fill="#333333"/>
</svg>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c0-.276142.22386-.5.5-.5h7.2929L13.5 3.70711V15c0 .2761-.2239.5-.5.5H3c-.27614 0-.5-.2239-.5-.5V1Z" fill="#fff" stroke="#BBB"/><path d="M9.5 1v2.7c0 .28003 0 .42004.0545.527.04793.09408.12442.17057.2185.2185.10696.0545.247.0545.527.0545H13" stroke="#BBB"/><path fill-rule="evenodd" clip-rule="evenodd" d="M9 7h3v1H9V7ZM8 9H5v1h3V9Zm0 2H5v1h3v-1Zm0-4H5v1h3V7Z" fill="#3AA133"/><path d="M10 9h5v5h-5V9Z" fill="#3AA133"/><path fill-rule="evenodd" clip-rule="evenodd" d="M11 10h1v1h-1v-1Zm2 1h-1v1h-1v1h1v-1h1v1h1v-1h-1v-1Zm0 0v-1h1v1h-1Z" fill="#fff"/></svg>

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 665 B

View File

@ -42,10 +42,14 @@
}
.tableHeaderCellViewers {
width: 29%;
width: 18%;
text-align: right;
}
.tableHeaderCellAction {
width: 23%;
}
.tableHeaderCellDownload {
width: 21%;
padding-right: 18px;
@ -220,7 +224,7 @@
}
.tableHeaderCellFileName {
width: 16%;
width: 9%;
}
.tableHeaderCellEditors {
@ -229,7 +233,12 @@
.tableHeaderCellViewers {
text-align: right;
width: 37%;
width: 9%;
}
.tableHeaderCellAction{
width: 11%;
padding-right: 82px;
}
.tableHeaderCellDownload {
@ -244,19 +253,24 @@
}
.tableHeaderCellEditors {
width: 26%;
width: 15%;
text-align: left;
}
.tableHeaderCellFileName {
width: 17%;
width: 28%;
}
.tableHeaderCellViewers {
width: 27%;
width: 6%;
text-align: right;
}
.tableHeaderCellAction{
width: 18%;
padding-right: 54px;
}
.tableHeaderCellDownload {
padding-right: 18px;
width: 20%;
@ -277,12 +291,17 @@
.tableRow td:first-child {
flex-grow: 0;
width: 15%;
width: 25%;
margin-right: auto;
}
.contentCells-icon {
width: 3%;
}
.firstContentCellViewers {
margin-left: 0;
}
}
@media (max-width: 890px) and (min-width: 769px ) {
@ -290,7 +309,7 @@
width: 20%;
}
.contentCells-shift {
padding-right: 28px;
padding-right: 27px;
}
.main-panel {
@ -323,11 +342,16 @@
.tableHeaderCellEditors {
text-align: left;
width: 31%;
width: 1%;
}
.tableHeaderCellViewers {
width: 18%;
width: 19%;
}
.tableHeaderCellAction {
width: 19%;
padding-right: 45px;
}
}
@ -429,8 +453,8 @@
.downloadContentCellShift {
max-width: 7%;
margin-right: -11px;
margin-left: auto;
margin-right: 24px;
margin-left: 0;
}
.contentCells-icon {
@ -438,13 +462,13 @@
}
.tableRow td:last-child {
width: 12%;
padding-right: 40px;
width: 7%;
padding-right: 0px;
border: none;
}
.contentCells-shift {
padding-right: 35px;
padding-right: 0px;
}
.downloadContentCellShift:after {
@ -530,6 +554,15 @@
height: 56px;
margin-bottom: 24px !important;
}
.button.hoar{
width: 18%;
height: 27px;
margin-bottom: 7px !important;
}
.button.converting{
width: 126px;
margin-top: 0;
}
}
@media (max-width: 560px) and (min-width: 510px) {
@ -538,7 +571,7 @@
}
.downloadContentCellShift {
padding-right: 45px;
padding-right: 16px;
max-width: 4%;
}
}
@ -558,7 +591,7 @@
.downloadContentCellShift {
max-width: 6%;
padding-right: 37px;
padding-right: 6px;
}
.firstContentCellShift {
@ -584,12 +617,12 @@
.downloadContentCellShift {
max-width: 3%;
padding-right: 37px;
padding-right: 0px;
padding-left: 0;
}
.firstContentCellShift {
margin-left: 1px;
margin-left: 2px;
flex-basis: 14%;
}
@ -619,7 +652,7 @@
.downloadContentCellShift {
max-width: 4%;
margin-right: -18px;
margin-right: 18px;
margin-left: -1px;
}
@ -628,7 +661,7 @@
}
.contentCells-icon{
width: 10%;
width: 12%;
}
footer table td {
margin: 0;

View File

@ -238,6 +238,52 @@ label .checkbox {
color: #FF6F3D;
}
.button.converting {
margin-top: -20px;
padding: 16px 16px;
}
.button.converting.wide {
padding: 16px 29px;
}
.button.hoar {
background: #EFEFEF;
border: 1px solid #EFEFEF;
margin-right: 7px;
margin-bottom: 7px;
width: 13%;
padding-left: 0;
padding-right: 0;
font-size: 11px;
}
.button.hoar.disable {
opacity: 30%;
cursor: default;
}
.button.hoar:not(.disable):hover {
background: #FF6F3D;
border: 1px solid #FF6F3D;
color: #FFFFFF;
}
.button.hoar.orange {
background: #FF6F3D;
border: 1px solid #FF6F3D;
color: #FFFFFF;
cursor: default;
}
.button.hoar.orange.disable {
background: #444444;
border: 1px solid #444444;
color: #FFFFFF;
cursor: default;
opacity: 100%;
}
.button.file-type {
font-size: 11px;
color: #FFFFFF;
@ -380,6 +426,32 @@ label .checkbox {
display: none;
}
#convertingProgress {
color: #333333;
display: none;
font-size: 12px;
margin: 30px 35px;
}
#convertingProgress .convertFileName{
background-position: left center;
background-repeat: no-repeat;
display: block;
font-size: 14px;
line-height: 160%;
overflow: hidden;
padding-left: 28px;
margin-bottom: 16px;
text-overflow: ellipsis;
white-space: nowrap;
}
#convertingProgress .describeUpload {
line-height: 150%;
letter-spacing: -0.02em;
padding: 16px 0;
}
.error-message {
background: url("images/error.svg") no-repeat scroll 4px 10px;
color: #CB0000;
@ -401,6 +473,10 @@ label .checkbox {
padding-left: 35px;
}
.waiting {
opacity: 30%;
}
.current {
background-image: url("images/loader16.gif");
}
@ -413,6 +489,12 @@ label .checkbox {
background-image: url("images/notdone.svg");
}
.convertPercent {
color: #FF6F3D;
font-weight: 700;
display: inline;
}
.step-descr {
display: block;
margin-left: 35px;
@ -420,6 +502,10 @@ label .checkbox {
line-height: 188%;
}
.step-descr.disable {
display: none;
}
.progress-descr {
letter-spacing: -0.02em;
line-height: 150%;
@ -525,21 +611,25 @@ footer a:hover {
white-space: nowrap;
}
.convertFileName.word,
.stored-edit.word,
.uploadFileName.word {
background-image: url("images/icon_docx.svg");
}
.convertFileName.cell,
.stored-edit.cell,
.uploadFileName.cell {
background-image: url("images/icon_xlsx.svg");
}
.convertFileName.slide,
.stored-edit.slide,
.uploadFileName.slide {
background-image: url("images/icon_pptx.svg");
}
.convertFileName.pdf,
.stored-edit.pdf,
.uploadFileName.pdf {
background-image: url("images/icon_pdf.svg");
@ -596,6 +686,11 @@ footer a:hover {
visibility: hidden;
}
.convertTable {
margin-top: 10px;
margin-left: 35px;
}
.tableRow {
background: transparent;
-moz-transition: all 0.2s ease-in-out;
@ -642,6 +737,12 @@ footer a:hover {
width: 11%;
}
.tableHeaderCellAction{
width: 13%;
text-align: right;
padding-right: 88px;
}
.tableHeaderCellDownload {
width: 13%;
text-align: right;
@ -666,7 +767,7 @@ footer a:hover {
}
.contentCells-shift {
padding-right: 44px;
padding-right: 43px;
}
.contentCells-icon {
@ -730,7 +831,7 @@ footer a:hover {
width: 100%;
}
.icon-delete {
.icon-action {
cursor: pointer;
}
@ -809,6 +910,13 @@ html {
position: relative;
}
.typeButtonsRow {
width: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
position: relative;
}
.tableRow td:first-child {
display: flex;
@ -817,11 +925,11 @@ html {
}
.tableHeaderCellFileName {
width: 30%;
width: 20%;
}
.tableHeaderCellEditors {
width: 28%;
width: 20%;
}
.tableHeaderCellViewers {

View File

@ -194,8 +194,7 @@
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
<td class="tableHeaderCell tableHeaderCellEditors contentCells-shift">Editors</td>
<td class="tableHeaderCell tableHeaderCellViewers">Viewers</td>
<td class="tableHeaderCell tableHeaderCellDownload">Download</td>
<td class="tableHeaderCell tableHeaderCellRemove">Remove</td>
<td class="tableHeaderCell tableHeaderCellAction">Action</td>
</tr>
</thead>
</table>
@ -303,14 +302,22 @@
<img src="app_themes/images/embeded.svg" alt="Open in embedded mode" title="Open in embedded mode"/>
</a>
</td>
<td class="contentCells contentCells-icon contentCells-shift downloadContentCellShift">
<% if (docType != null ) { %>
<td class="contentCells contentCells-icon">
<a class="convert-file" data="<%= storedFile.Name %>" data-type="<%= docType %>">
<img class="icon-action" src="app_themes/images/convert.svg" alt="Convert" title="Convert" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-icon downloadContentCellShift"></td>
<% } %>
<td class="contentCells contentCells-icon downloadContentCellShift">
<a href="webeditor.ashx?type=download&fileName=<%= HttpUtility.UrlEncode(storedFile.Name) %>">
<img class="icon-download" src="app_themes/images/download.svg" alt="Download" title="Download" />
</a>
</td>
<td class="contentCells contentCells-icon contentCells-shift">
<a class="delete-file" data-filename="<%= storedFile.Name %>">
<img class="icon-delete" src="app_themes/images/delete.svg" alt="Delete" title="Delete" />
<img class="icon-action" src="app_themes/images/delete.svg" alt="Delete" title="Delete" />
</a>
</td>
</tr>
@ -379,6 +386,32 @@
</div>
</div>
<div id="convertingProgress">
<div id="convertingSteps">
<span id="convertFileName" class="convertFileName"></span>
<span id="convertStep1" class="step">1. Select a format file to convert</span>
<span class="step-descr">The converting speed depends on file size and additional elements it contains.</span>
<table cellspacing="0" cellpadding="0" width="100%" class="convertTable">
<tbody>
<tr class="typeButtonsRow" id="convTypes"></tr>
</tbody>
</table>
<br />
<span id="convertStep2" class="step">2. File conversion</span>
<span class="step-descr disable" id="convert-descr">The file is converted <div class="convertPercent" id="convertPercent">0 %</div></span>
<span class="step-error hidden" id="convert-error"></span>
<div class="describeUpload">Note the speed of all operations depends on your connection quality and server location.</div>
<input type="hidden" name="hiddenFileName" id="hiddenFileName" />
</div>
<br />
<div class="buttonsMobile">
<div id="downloadConverted" class="button converting orange disable">DOWNLOAD</div>
<div id="beginViewConverted" class="button converting wide gray disable">VIEW</div>
<div id="beginEditConverted" class="button converting wide gray disable">EDIT</div>
<div id="cancelEdit" class="button converting gray">CANCEL</div>
</div>
</div>
<span id="loadScripts" data-docs="<%= UrlPreloadScripts %>"></span>
<footer>

View File

@ -447,8 +447,15 @@ namespace OnlineEditorsExample
conversionExtension = fileExt.ToString();
}
object keepOriginal;
bool removeOriginal = true;
if (body.TryGetValue("keepOriginal", out keepOriginal) && !String.IsNullOrEmpty(keepOriginal.ToString()))
{
removeOriginal = keepOriginal.ToString().ToLower() != "true";
}
// check if the file with such an extension can be converted
if (ConvertExts.Contains("." + extension))
if (ConvertExts.Contains("." + extension) || conversionExtension != "ooxml")
{
// generate document key
var key = ServiceConverter.GenerateRevisionId(FileUri(_fileName, true));
@ -469,9 +476,13 @@ namespace OnlineEditorsExample
}
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
var newFileType = newFileData["fileType"];
if (!FormatManager.All().Any(f => f.Name == newFileType && f.Type != ""))
{
return "{\"step\": \"" + result + "\", \"filename\": \"" + newFileUri + "\", \"error\": \"FileTypeIsNotSupported\"}";
}
// get a file name of an internal file extension with an index if the file with such a name already exists
var fileName = GetCorrectName(Path.GetFileNameWithoutExtension(_fileName) + newFileType);
var fileName = GetCorrectName(Path.GetFileNameWithoutExtension(_fileName) + "." + newFileType);
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
@ -493,17 +504,21 @@ namespace OnlineEditorsExample
}
}
// remove the original file and its history if it exists
var storagePath = StoragePath(_fileName, null);
var histDir = HistoryDir(storagePath);
File.Delete(storagePath);
if (Directory.Exists(histDir)) Directory.Delete(histDir, true);
if (removeOriginal)
{
// remove the original file and its history if it exists
var storagePath = StoragePath(_fileName, null);
var histDir = HistoryDir(storagePath);
File.Delete(storagePath);
if (Directory.Exists(histDir)) Directory.Delete(histDir, true);
}
// create meta information about the converted file with user id and name specified
_fileName = fileName;
var id = context.Request.Cookies.GetOrDefault("uid", null);
var user = Users.getUser(id); // get the user
DocEditor.CreateMeta(_fileName, user.id, user.name, null);
return "{\"step\": \"" + result + "\", \"filename\": \"" + _fileName + "\"}";
}
return "{ \"filename\" : \"" + _fileName + "\"}";

View File

@ -1,3 +1,21 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
function deleteFile(event) {
let filename = event.currentTarget.getAttribute("data");
filename = encodeURIComponent(filename);

View File

@ -304,6 +304,134 @@ if (typeof jQuery != "undefined") {
jq("#embeddedView").attr("src", url);
});
jq(document).on("click", "#beginEditConverted:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').attr("data"));
var url = "doceditor.aspx?fileID=" + fileId;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginViewConverted:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').attr("data"));
var url = "doceditor.aspx?editorsMode=view&fileID=" + fileId;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#downloadConverted:not(.disable)", function () {
var fileId = jq('#hiddenFileName').attr("data");
if (jq("#downloadConverted").attr("data") == "fromConverter") window.location.assign(fileId);
else window.open("webeditor.ashx?type=download&fileName=" + encodeURIComponent(fileId), "_blank");
});
jq(document).on("click", ".convert-file", function () {
const currentElement = jq(this);
var fileName = currentElement.attr("data");
var type = currentElement.attr("data-type");
jq.blockUI({
theme: true,
title: "Converting file" + "<div class=\"dialog-close\"></div>",
message: jq("#convertingProgress"),
overlayCSS: { "background-color": "#aaa" },
themedCSS: { width: "539px", top: "20%", left: "50%", marginLeft: "-269px" }
});
jq("#convertFileName").text(decodeURIComponent(fileName));
jq("#convertFileName").removeClass("word slide cell");
jq("#convertFileName").addClass(type);
jq("#convTypes").empty();
let format = formatManager.findByExtension(fileName.split('.').pop());
if (format) {
format.convert.forEach(ext => {
jq("#convTypes").append(jq(`<td name="convertingTypeButton" id="wordTo${ext}" class="button hoar" data="${ext}">${ext}</td>`));
});
}
jq("#hiddenFileName").val(fileName);
jq("#convertStep1").addClass("done");
jq("#convertStep2").addClass("waiting");
});
jq(document).on("click", "td[name='convertingTypeButton']:not(.disable, .orange)", function () {
const currentElement = jq(this);
let id = currentElement[0].id;
let fileExt = jq(`#${id}`).attr("data");
jq(`#${id}`).addClass("orange");
jq("td[name='convertingTypeButton']").addClass("disable");
jq("#convertStep2").removeClass("waiting").removeClass("done").addClass("current");
jq("#convertStep2").text('2. File conversion');
jq("#convert-descr").removeClass("disable");
jq("#convertPercent").text("0 %");
jq("#hiddenFileName").attr("placeholder",fileExt);
jq("#downloadConverted").addClass("disable");
jq("#beginEditConverted").addClass("disable");
jq("#beginViewConverted").addClass("disable");
mustReload = true;
convertFile();
});
function convertFile (filePass) {
let fileName = decodeURIComponent(jq("#hiddenFileName").val());
let fileExt = jq("#hiddenFileName").attr("placeholder");
filePass = filePass ? filePass : null;
if (timer != null) {
clearTimeout(timer);
}
timer = setTimeout(function () {
jq.ajax({
async: true,
contentType: "text/xml",
type: "post",
dataType: "json",
data: JSON.stringify({filename: fileName, filePass: filePass, lang: language, fileExt: fileExt, keepOriginal: true}),
url: "webeditor.ashx?type=convert",
complete: function (data) {
try {
var response = jq.parseJSON(data.responseText);
} catch (e) {
response = { error: e };
}
if (!response.filename && !response.step && response.error) {
jq("#convertStep2").removeClass("current").addClass("error");
jq("#convertStep2").text(`2. File conversion to ${fileExt}`);
jq("#convert-error").removeClass("hidden");
jq("#convert-error").text(`${response.error}`);
jq("td[name='convertingTypeButton']").removeClass("disable orange");
return;
}
if (response.step != undefined && response.step != 100) {
jq("#convertPercent").text(`${response.step} %`);
convertFile();
} else {
jq("#convertPercent").text(`${response.step} %`);
jq("#convertStep2").removeClass("current").addClass("done");
jq("#convertStep2").text(`2. File conversion to ${fileExt}`);
jq("#downloadConverted").removeClass("disable");
if (response.error !== "FileTypeIsNotSupported") {
jq("#hiddenFileName").attr("data",response.filename);
jq("#beginEditConverted").removeClass("disable");
jq("#beginViewConverted").removeClass("disable");
jq("#downloadConverted").attr("data","fromStorage");
} else {
let newFilename = fileName.split('.').slice(0,-1).join('.')
jq("#hiddenFileName").attr("data",response.filename.split("&filename=download").join(`&filename=${newFilename}`));
jq("#downloadConverted").attr("data","fromConverter");
}
jq("td[name='convertingTypeButton']").removeClass("disable orange");
}
}
});
}, 1000);
}
jq(document).on("click", "#cancelEdit, .dialog-close", function () {
jq('#hiddenFileName').val("");
jq("#embeddedView").attr("src", "");

View File

@ -0,0 +1,14 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
[*.go]
indent_style = tab
[*.{js, ts, json, html}]
indent_style = space
indent_size = 4

View File

@ -0,0 +1,2 @@
filestore
assets/*

View File

@ -0,0 +1,46 @@
linters:
enable-all: true
disable:
- cyclop
- depguard
- dogsled
- err113
- errchkjson
- execinquery
- exhaustruct
- exportloopref
- funlen
- gochecknoglobals
- gocognit
- goconst
- godox
- gofumpt
- gomnd
- gosec
- interfacebloat
- ireturn
- mirror
- mnd
- musttag
- nestif
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- perfsprint
- prealloc
- revive
- varnamelen
- wrapcheck
- wsl
linters-settings:
errcheck:
exclude-functions:
- (net/http.ResponseWriter).Write
lll:
line-length: 120
gofmt:
simplify: false
stylecheck:
checks: ["all", "-ST1016", "-ST1003"]

View File

@ -0,0 +1,29 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
fx - An application framework for Go that makes dependency injection easy. (https://github.com/uber-go/fx).
License: MIT
License File: fx.license
golang-jwt - A go implementation of JSON Web Tokens. (https://github.com/golang-jwt/jwt).
License: MIT
License File: golang-jwt.license
gorilla/mux - Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler. (https://github.com/gorilla/mux).
License: BSD-3-Clause License
License File: mux.license
mapstructure - Go library for decoding generic map values into native Go structures and vice versa. (https://github.com/mitchellh/mapstructure)
License: MIT
License File: mapstructure.license
schema - Package gorilla/schema fills a struct with form values. (https://github.com/gorilla/schema)
License: BSD-3-Clause License
License File: schema.license
viper - Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats. (https://github.com/spf13/viper).
License: MIT
License File: viper.license
zap - Blazing fast, structured, leveled logging in Go. (https://github.com/uber-go/zap).
License: MIT
License File: zap.license

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,62 @@
## Overview
This example will help you integrate ONLYOFFICE Docs into your web application written in Go.
It is aimed at testing the editors. Please, do not use it for production without proper modifications.
## Installation
### Step 1. Install ONLYOFFICE Docs
Download and install ONLYOFFICE Docs (packaged as Document Server).
See the detailed guide to learn how to install Document Server [for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx).
### Step 2. Download the Go code for the editors integration
Download the [Go example](https://api.onlyoffice.com/editors/demopreview) from our site.
To connect the editors to your website, specify the path to the editors installation, server protocol, address and port in the *configuration.env* file:
```
SERVER_ADDRESS=http(s)://address (optional)
SERVER_PORT=port
DOC_SERVER_HOST=http://documentserver/
JWT_IS_ENABLED=flag
JWT_SECRET=secret
JWT_HEADER=Authorization
```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
**address** is the address of the server, **port** is the server port.
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) it the *templates/editor.html* file.
### Step 3. Install the prerequisites
To run the Go example code, install the Go compiler:
* Go (download from [The Go lang website](https://golang.org/);
### Step 4. Set environment variables
Having installed the compiler, update golang env variables:
```
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin
```
### Step 5. Start the application
1. Go to the project root.
2. Run:
```
go run main.go
```
3. In your browser go to **server.address** and **server.port**:
### Step 6. Check accessibility
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.

View File

@ -0,0 +1,71 @@
{
"VERSION": "1.11.0",
"SERVER_ADDRESS" : "",
"SERVER_PORT" : 3000,
"DOC_SERVER_HOST" : "http://documentserver/",
"DOC_SERVER_CONVERTER_URL" : "converter",
"DOC_SERVER_API_URL" : "web-apps/apps/api/documents/api.js",
"DOC_SERVER_PRELOADER_URL" : "web-apps/apps/api/documents/cache-scripts.html",
"DOC_SERVER_COMMAND_URL" : "command",
"JWT_IS_ENABLED" : false,
"JWT_SECRET" : "secret",
"JWT_HEADER" : "Authorization",
"STORAGE_PATH" : "filestore",
"LOGGER_DEBUG" : true,
"FORGOTTEN_ENABLED": true,
"PLUGINS" : "{\"pluginsData\":[]}",
"LANGUAGES": {
"en": "English",
"ar": "Arabic",
"hy": "Armenian",
"az": "Azerbaijani",
"eu": "Basque",
"be": "Belarusian",
"bg": "Bulgarian",
"ca": "Catalan",
"zh": "Chinese (Simplified)",
"zh-TW": "Chinese (Traditional)",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"en-GB": "English (United Kingdom)",
"fi": "Finnish",
"fr": "French",
"gl": "Galego",
"de": "German",
"el": "Greek",
"he-IL": "Hebrew (Israel)",
"hu": "Hungarian",
"id": "Indonesian",
"it": "Italian",
"ja": "Japanese",
"ko": "Korean",
"lo": "Lao",
"lv": "Latvian",
"ms": "Malay (Malaysia)",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese (Brazil)",
"pt-PT": "Portuguese (Portugal)",
"ro": "Romanian",
"ru": "Russian",
"sr-Cyrl-RS": "Serbian (Cyrillic)",
"sr-Latn-RS": "Serbian (Latin)",
"si": "Sinhala (Sri Lanka)",
"sk": "Slovak",
"sl": "Slovenian",
"es": "Spanish",
"sv": "Swedish",
"tr": "Turkish",
"uk": "Ukrainian",
"vi": "Vietnamese",
"aa-AA": "Test Language"
}
}

View File

@ -0,0 +1,32 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package config
type Extensions struct {
Viewed []string `json:"viewed"`
Edited []string `json:"edited"`
Converted []string `json:"converted"`
Filled []string `json:"filled"`
}
type ExtensionTypes struct {
Spreadsheet []string `json:"spreadsheet"`
Presentation []string `json:"presentation"`
Document []string `json:"document"`
Pdf []string `json:"pdf"`
}

View File

@ -0,0 +1,105 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package config
import (
"path/filepath"
"runtime"
"github.com/ONLYOFFICE/document-server-integration/utils"
"github.com/spf13/viper"
"go.uber.org/fx"
)
type ApplicationConfig struct {
Version string `mapstructure:"VERSION"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
ServerPort string `mapstructure:"SERVER_PORT"`
DocumentServerHost string `mapstructure:"DOC_SERVER_HOST"`
DocumentServerConverter string `mapstructure:"DOC_SERVER_CONVERTER_URL"`
DocumentServerApi string `mapstructure:"DOC_SERVER_API_URL"`
DocumentServerPreloader string `mapstructure:"DOC_SERVER_PRELOADER_URL"`
DocumentServerCommandUrl string `mapstructure:"DOC_SERVER_COMMAND_URL"`
JwtEnabled bool `mapstructure:"JWT_IS_ENABLED"`
JwtHeader string `mapstructure:"JWT_HEADER"`
JwtSecret string `mapstructure:"JWT_SECRET"`
StoragePath string `mapstructure:"STORAGE_PATH"`
Plugins string `mapstructure:"PLUGINS"`
LoggerDebug bool `mapstructure:"LOGGER_DEBUG"`
ForgottenEnabled bool `mapstructure:"FORGOTTEN_ENABLED"`
Languages map[string]string `mapstructure:"LANGUAGES"`
}
type SpecificationConfig struct {
Extensions Extensions `mapstructure:"extensions"`
ExtensionTypes ExtensionTypes `mapstructure:"extension_types"`
}
func NewConfiguration() (app_config ApplicationConfig, err error) {
_, b, _, _ := runtime.Caller(0)
basepath := filepath.Dir(b)
viper.AddConfigPath(basepath)
viper.SetConfigName("configuration")
viper.SetConfigType("json")
viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
return ApplicationConfig{}, err
}
err = viper.Unmarshal(&app_config)
if err != nil {
return ApplicationConfig{}, err
}
return
}
func NewSpecification() (specification SpecificationConfig, err error) {
fm, err := utils.NewFormatManager()
if err != nil {
return SpecificationConfig{}, err
}
exts := Extensions{
fm.GetViewedExtensions(),
fm.GetEditedExtensions(),
fm.GetConvertedExtensions(),
fm.GetFilledExtensions(),
}
extTypes := ExtensionTypes{
fm.GetSpreadsheetExtensions(),
fm.GetPresentationExtensions(),
fm.GetDocumentExtensions(),
fm.GetPdfExtensions(),
}
specification = SpecificationConfig{
exts,
extTypes,
}
return
}
var ConfigurationModule = fx.Options(
fx.Provide(NewConfiguration),
fx.Provide(NewSpecification),
)

View File

@ -0,0 +1,34 @@
module github.com/ONLYOFFICE/document-server-integration
go 1.21
require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/gorilla/mux v1.8.1
github.com/gorilla/schema v1.4.1
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/viper v1.19.0
go.uber.org/fx v1.22.2
go.uber.org/zap v1.27.0
)
require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -0,0 +1,82 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.22.2 h1:iPW+OPxv0G8w75OemJ1RAnTUrF55zOJlXlo1TbJ0Buw=
go.uber.org/fx v1.22.2/go.mod h1:o/D9n+2mLP6v1EG+qsdT1O8wKopYAsqZasju97SDFCU=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -0,0 +1,29 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
fx - An application framework for Go that makes dependency injection easy. (https://github.com/uber-go/fx).
License: MIT
License File: fx.license
golang-jwt - A go implementation of JSON Web Tokens. (https://github.com/golang-jwt/jwt).
License: MIT
License File: golang-jwt.license
gorilla/mux - Package gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler. (https://github.com/gorilla/mux).
License: BSD-3-Clause License
License File: mux.license
mapstructure - Go library for decoding generic map values into native Go structures and vice versa. (https://github.com/mitchellh/mapstructure)
License: MIT
License File: mapstructure.license
schema - Package gorilla/schema fills a struct with form values. (https://github.com/gorilla/schema)
License: BSD-3-Clause License
License File: schema.license
viper - Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats. (https://github.com/spf13/viper).
License: MIT
License File: viper.license
zap - Blazing fast, structured, leveled logging in Go. (https://github.com/uber-go/zap).
License: MIT
License File: zap.license

View File

@ -0,0 +1,19 @@
Copyright (c) 2016-2018 Uber Technologies, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,9 @@
Copyright (c) 2012 Dave Grijalva
Copyright (c) 2021 golang-jwt maintainers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 Mitchell Hashimoto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,27 @@
Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,27 @@
Copyright (c) 2023 The Gorilla Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Steve Francia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,19 @@
Copyright (c) 2016-2017 Uber Technologies, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,47 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package main
import (
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server"
"github.com/ONLYOFFICE/document-server-integration/server/api"
defaultApi "github.com/ONLYOFFICE/document-server-integration/server/api/default"
bootstrapper "github.com/ONLYOFFICE/document-server-integration/server/config"
"github.com/ONLYOFFICE/document-server-integration/server/handlers"
dhandlers "github.com/ONLYOFFICE/document-server-integration/server/handlers/default"
"github.com/ONLYOFFICE/document-server-integration/server/log"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
dmanagers "github.com/ONLYOFFICE/document-server-integration/server/managers/default"
"go.uber.org/fx"
)
func main() {
fx.New(
fx.Provide(api.New),
fx.Provide(managers.New),
fx.Provide(handlers.New),
fx.Provide(server.New),
fx.Invoke(bootstrapper.Initialize),
config.ConfigurationModule,
log.LoggingModule,
dhandlers.DefaultHandlersModule,
dmanagers.DefaultManagersModule,
defaultApi.DefaultServerEndpointsHandlerModule,
).Run()
}

View File

@ -0,0 +1,63 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package api
import (
"net/http"
)
type FileOperationsEndpointsHandler interface {
Callback(w http.ResponseWriter, r *http.Request)
Convert(w http.ResponseWriter, r *http.Request)
Create(w http.ResponseWriter, r *http.Request)
Download(w http.ResponseWriter, r *http.Request)
Remove(w http.ResponseWriter, r *http.Request)
Rename(w http.ResponseWriter, r *http.Request)
Restore(w http.ResponseWriter, r *http.Request)
Upload(w http.ResponseWriter, r *http.Request)
}
type InfoEndpointsHandler interface {
Files(w http.ResponseWriter, r *http.Request)
Formats(w http.ResponseWriter, r *http.Request)
History(w http.ResponseWriter, r *http.Request)
HistoryObj(w http.ResponseWriter, r *http.Request)
Reference(w http.ResponseWriter, r *http.Request)
}
type PagesEndpointsHandler interface {
Editor(w http.ResponseWriter, r *http.Request)
Forgotten(w http.ResponseWriter, r *http.Request)
Index(w http.ResponseWriter, r *http.Request)
}
type ServerEndpointsHandler interface {
FileOperationsEndpointsHandler
InfoEndpointsHandler
PagesEndpointsHandler
}
type ServerAPI struct {
ServerEndpointsHandler
}
func New(endpointsHandler ServerEndpointsHandler) *ServerAPI {
return &ServerAPI{
endpointsHandler,
}
}

View File

@ -0,0 +1,69 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"fmt"
"html/template"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server/api"
"github.com/ONLYOFFICE/document-server-integration/server/handlers"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/gorilla/schema"
"go.uber.org/zap"
)
type DefaultServerEndpointsHandler struct {
logger *zap.SugaredLogger
config config.ApplicationConfig
specification config.SpecificationConfig
*handlers.CallbackRegistry
*managers.Managers
}
func NewDefaultServerEndpointsHandler(logger *zap.SugaredLogger, config config.ApplicationConfig,
spec config.SpecificationConfig, reg *handlers.CallbackRegistry,
managers *managers.Managers) api.ServerEndpointsHandler {
return &DefaultServerEndpointsHandler{
logger,
config,
spec,
reg,
managers,
}
}
func generateUrl(r *http.Request) string {
scheme := "http"
if r.Header.Get("X-Forwarded-Proto") != "" {
scheme = r.Header.Get("X-Forwarded-Proto")
}
if r.TLS != nil {
scheme = "https"
}
return fmt.Sprintf("%s://%s", scheme, r.Host)
}
var decoder = schema.NewDecoder()
var indexTemplate = template.Must(template.ParseFiles("templates/index.html"))
var forgottenTemplate = template.Must(template.ParseFiles("templates/forgotten.html"))
var editorTemplate = template.Must(template.ParseFiles("templates/editor.html"))

View File

@ -0,0 +1,57 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Callback(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
filename, userAddress := query.Get("filename"), query.Get("user_address")
if filename == "" || userAddress == "" {
shared.SendDocumentServerRespose(w, true)
return
}
var body models.Callback
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("Callback body decoding error")
shared.SendDocumentServerRespose(w, true)
return
}
if err := srv.Managers.JwtManager.ParseCallback(&body, r.Header.Get(srv.config.JwtHeader)); err != nil {
srv.logger.Error(err.Error())
shared.SendDocumentServerRespose(w, true)
return
}
body.Filename = filename
body.UserAddress = userAddress
if err := srv.CallbackRegistry.HandleIncomingCode(&body); err != nil {
shared.SendDocumentServerRespose(w, true)
return
}
shared.SendDocumentServerRespose(w, false)
}

View File

@ -0,0 +1,155 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"net/http"
"time"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Convert(w http.ResponseWriter, r *http.Request) {
_, uid := shared.GetCookiesInfo(r.Cookies())
if uid == "" {
srv.logger.Errorf("invalid user id")
shared.SendDocumentServerRespose(w, true)
return
}
user, err := srv.UserManager.GetUserById(uid)
if err != nil {
srv.logger.Errorf("could not find user with id: %s", uid)
shared.SendDocumentServerRespose(w, true)
return
}
srv.logger.Debug("A new convert call")
var payload managers.ConvertRequest
err = json.NewDecoder(r.Body).Decode(&payload)
if err != nil {
srv.logger.Error(err.Error())
shared.SendDocumentServerRespose(w, true)
return
}
filename := payload.Filename
response := managers.ConvertResponse{Filename: filename}
defer shared.SendResponse(w, &response)
remoteAddr := generateUrl(r)
if srv.config.ServerAddress != "" {
remoteAddr = srv.config.ServerAddress
}
fileUrl := srv.StorageManager.GeneratePublicFileUri(filename, remoteAddr, managers.FileMeta{})
fileExt := utils.GetFileExt(filename, true)
toExt := "ooxml"
if payload.Filetype != "" {
toExt = payload.Filetype
}
keepOriginal := payload.Keeporiginal
if srv.DocumentManager.IsDocumentConvertable(filename) || payload.Filetype != "" {
key, err := srv.StorageManager.GenerateFileHash(filename)
if err != nil {
response.Error = err.Error()
srv.logger.Errorf("File conversion error: %s", err.Error())
return
}
newUrl, newExt, err := srv.ConversionManager.GetConverterUri(fileUrl, fileExt, toExt, key, true)
if err != nil {
response.Error = err.Error()
srv.logger.Errorf("File conversion error: %s", err.Error())
return
}
if newUrl == "" {
response.Step = 1
} else {
response.Step = 100
supportedExt := true
fm, err := utils.NewFormatManager()
for _, f := range fm.GetFormats() {
if f.Name == newExt && len(f.Actions) == 0 {
supportedExt = false
break
}
}
if !supportedExt && err == nil {
response.Error = "FileTypeIsNotSupported"
response.Filename = newUrl
return
} else if err != nil {
response.Error = err.Error()
return
}
correctName, err := srv.StorageManager.GenerateVersionedFilename(
utils.GetFileNameWithoutExt(filename) + "." + newExt,
)
if err != nil {
response.Error = err.Error()
srv.logger.Errorf("File conversion error: %s", err.Error())
return
}
err = srv.StorageManager.SaveFileFromUri(models.Callback{
Url: newUrl,
Filename: correctName,
UserAddress: r.Host,
})
if err != nil {
response.Error = err.Error()
return
}
if !keepOriginal {
err = srv.StorageManager.RemoveFile(filename)
if err != nil {
srv.logger.Errorf("File deletion error: %s", err.Error())
}
}
response.Filename = correctName
err = srv.HistoryManager.CreateMeta(response.Filename, models.History{
ServerVersion: srv.config.Version,
Changes: []models.Changes{
{
Created: time.Now().UTC().Format("2006-02-1 15:04:05"),
User: models.User{
Id: user.Id,
Username: user.Username,
},
},
},
})
if err != nil {
srv.logger.Errorf("Meta creation error: %s", err.Error())
}
}
}
}

View File

@ -0,0 +1,178 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"fmt"
"net/http"
"os"
"path"
"strings"
"time"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Create(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
var body map[string]string
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("Reference body decoding error")
shared.SendDocumentServerRespose(w, true)
return
}
fileName, url := body["title"], body["url"]
if fileName == "" || url == "" {
srv.logger.Error("empty url or title")
shared.SendCustomErrorResponse(w, "empty url or title")
return
}
_, uid := shared.GetCookiesInfo(r.Cookies())
user, err := srv.UserManager.GetUserById(uid)
if err != nil {
srv.logger.Errorf("could not find user with id: %s", uid)
shared.SendCustomErrorResponse(w, err.Error())
return
}
fileExt := utils.GetFileExt(fileName, true)
if strings.TrimSpace(fileExt) == "" || !utils.IsInList(fileExt, srv.specification.Extensions.Viewed) {
srv.logger.Errorf("%s extension is not supported", fileExt)
shared.SendCustomErrorResponse(w, "extension is not supported")
return
}
correctName, err := srv.StorageManager.GenerateVersionedFilename(fileName)
if err != nil {
srv.logger.Errorf("file saving error: %s", err.Error())
shared.SendCustomErrorResponse(w, "file saving error")
return
}
err = srv.StorageManager.SaveFileFromUri(models.Callback{
Url: url,
Filename: correctName,
UserAddress: r.Host,
})
if err != nil {
srv.logger.Errorf("file saving error: %s", err.Error())
shared.SendCustomErrorResponse(w, "file saving error")
return
}
err = srv.HistoryManager.CreateMeta(correctName, models.History{
ServerVersion: srv.config.Version,
Changes: []models.Changes{
{
Created: time.Now().UTC().Format("2006-02-1 15:04:05"),
User: models.User{
Id: user.Id,
Username: user.Username,
},
},
},
})
if err != nil {
srv.logger.Errorf("meta creation error: %s", err.Error())
}
return
}
query := r.URL.Query()
fileExt, isSample := query.Get("fileExt"), query.Get("sample")
if strings.TrimSpace(fileExt) == "" || !utils.IsInList(fileExt, srv.specification.Extensions.Edited) {
srv.logger.Errorf("%s extension is not supported", fileExt)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
_, uid := shared.GetCookiesInfo(r.Cookies())
if uid == "" {
srv.logger.Errorf("user id is blank")
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
user, err := srv.UserManager.GetUserById(uid)
if err != nil {
srv.logger.Errorf("could not find user with id: %s", uid)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
srv.logger.Debugf("Creating a new %s file", fileExt)
sampleType := "new"
if strings.TrimSpace(isSample) != "" {
sampleType = "sample"
}
filename := fmt.Sprintf("%s.%s", sampleType, fileExt)
file, err := os.Open(path.Join("static/assets/document-templates", sampleType, filename))
if err != nil {
srv.logger.Errorf("could not create a new file: %s", err.Error())
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
defer file.Close()
filename, err = srv.StorageManager.GenerateVersionedFilename(filename)
if err != nil {
srv.logger.Errorf("could not generated versioned filename: %s", filename)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
fpath, err := srv.StorageManager.GenerateFilePath(filename)
if err != nil {
srv.logger.Errorf("could not generated file path: %s", filename)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
err = srv.StorageManager.CreateFile(file, fpath)
if err != nil {
srv.logger.Errorf("could not create file: %s", filename)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
err = srv.HistoryManager.CreateMeta(filename, models.History{
ServerVersion: srv.config.Version,
Changes: []models.Changes{
{
Created: time.Now().UTC().Format("2006-02-1 15:04:05"),
User: models.User{
Id: user.Id,
Username: user.Username,
},
},
},
})
if err != nil {
srv.logger.Errorf("could not create file meta: %s", filename)
}
http.Redirect(w, r, "/editor?filename="+filename, http.StatusSeeOther)
}

View File

@ -0,0 +1,44 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Download(w http.ResponseWriter, r *http.Request) {
filename := r.URL.Query().Get("fileName")
srv.logger.Debugf("A new download call (%s)", filename)
if filename == "" {
shared.SendDocumentServerRespose(w, true)
return
}
var meta managers.FileMeta
fileUrl := srv.StorageManager.GenerateFilestoreUri(filename, meta)
if fileUrl == "" {
shared.SendDocumentServerRespose(w, true)
return
}
http.Redirect(w, r, fileUrl, http.StatusMovedPermanently)
}

View File

@ -0,0 +1,84 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Editor(w http.ResponseWriter, r *http.Request) {
var editorParameters managers.Editor
if err := decoder.Decode(&editorParameters, r.URL.Query()); err != nil {
srv.logger.Error("Invalid query parameters")
return
}
if err := editorParameters.IsValid(); err != nil {
srv.logger.Errorf("Editor parameters are invalid: %s", err.Error())
return
}
srv.logger.Debug("A new editor call")
editorParameters.Language, editorParameters.UserId = shared.GetCookiesInfo(r.Cookies())
remoteAddr := generateUrl(r)
if srv.config.ServerAddress != "" {
remoteAddr = srv.config.ServerAddress
}
config, err := srv.Managers.DocumentManager.BuildDocumentConfig(editorParameters, remoteAddr)
if err != nil {
srv.logger.Errorf("A document manager error has occurred: %s", err.Error())
return
}
var usersForMentions, usersForProtect, usersInfo []models.UserInfo
if config.EditorConfig.User.Id != "uid-0" {
usersForMentions = srv.GetUsersForMentions(config.EditorConfig.User.Id)
usersForProtect = srv.GetUsersForProtect(config.EditorConfig.User.Id, remoteAddr)
usersInfo = srv.GetUsersInfo(remoteAddr)
}
data := map[string]interface{}{
"apijs": srv.config.DocumentServerHost + srv.config.DocumentServerApi,
"config": config,
"actionLink": editorParameters.ActionLink,
"docType": config.DocumentType,
"usersForProtect": usersForProtect,
"usersForMentions": usersForMentions,
"usersInfo": usersInfo,
"dataInsertImage": map[string]interface{}{
"fileType": "svg",
"url": remoteAddr + "/static/images/logo.svg",
},
"dataDocument": map[string]interface{}{
"fileType": "docx",
"url": remoteAddr + "/static/assets/document-templates/sample/sample.docx",
},
"dataSpreadsheet": map[string]interface{}{
"fileType": "csv",
"url": remoteAddr + "/static/assets/document-templates/sample/csv.csv",
},
}
editorTemplate.Execute(w, data) // nolint: errcheck
}

View File

@ -0,0 +1,37 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"fmt"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Files(w http.ResponseWriter, r *http.Request) {
srv.logger.Debug("A new files call")
files, err := srv.Managers.StorageManager.GetStoredFiles(r.Host)
if err != nil {
srv.logger.Errorf("could not fetch files: %s", err.Error())
shared.SendCustomErrorResponse(w, fmt.Sprintf("could not fetch files: %s", err.Error()))
return
}
shared.SendResponse(w, files)
}

View File

@ -0,0 +1,85 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Forgotten(w http.ResponseWriter, r *http.Request) {
srv.logger.Debug("A new forgotten call")
if !srv.config.ForgottenEnabled {
shared.SendCustomErrorResponse(w, "The forgotten page is disabled")
return
}
if r.Method == http.MethodDelete {
filename := r.URL.Query().Get("fileName")
if filename == "" {
shared.SendCustomErrorResponse(w, "No filename")
} else {
r, err := srv.Managers.CommandManager.CommandRequest("deleteForgotten", filename, nil)
if err != nil {
srv.logger.Errorf("could not delete forgotten file: %s", err.Error())
shared.SendDocumentServerRespose(w, true)
} else {
defer r.Body.Close()
w.WriteHeader(http.StatusNoContent)
shared.SendDocumentServerRespose(w, false)
}
}
return
}
var forgottenList models.ForgottenList
res, err := srv.Managers.CommandManager.CommandRequest("getForgottenList", "", nil)
if err != nil {
srv.logger.Errorf("could not fetch forgotten files: %s", err.Error())
}
defer res.Body.Close()
if err = json.NewDecoder(res.Body).Decode(&forgottenList); err != nil {
srv.logger.Errorf("could not parse forgotten files: %s", err.Error())
}
var files []models.ForgottenFile
for _, key := range forgottenList.Keys {
var file models.ForgottenFile
res, err = srv.CommandRequest("getForgotten", key, nil)
if err != nil {
srv.logger.Errorf("could not fetch forgotten file[%s]: %s", file.Key, err.Error())
} else {
defer res.Body.Close()
if err = json.NewDecoder(res.Body).Decode(&file); err != nil {
srv.logger.Errorf("could not parse forgotten file[%s]: %s", file.Key, err.Error())
} else {
file.Type = srv.Managers.ConversionManager.GetFileType(file.Url)
files = append(files, file)
}
}
}
data := map[string]interface{}{
"Files": files,
}
forgottenTemplate.Execute(w, data) // nolint: errcheck
}

View File

@ -0,0 +1,38 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"fmt"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Formats(w http.ResponseWriter, r *http.Request) {
srv.logger.Debug("A new formats call")
fm, err := utils.NewFormatManager()
if err != nil {
srv.logger.Errorf("could not fetch formats: %s", err.Error())
shared.SendCustomErrorResponse(w, fmt.Sprintf("could not fetch formats: %s", err.Error()))
return
}
shared.SendResponse(w, fm.GetFormats())
}

View File

@ -0,0 +1,57 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"net/http"
"strconv"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) History(w http.ResponseWriter, r *http.Request) {
filename := r.URL.Query().Get("fileName")
file := r.URL.Query().Get("file")
version, err := strconv.Atoi(r.URL.Query().Get("ver"))
if err != nil {
srv.logger.Errorf("Could not parse file version: %s", err.Error())
shared.SendDocumentServerRespose(w, true)
return
}
srv.logger.Debugf("A new history call (%s)", filename)
if filename == "" {
srv.logger.Errorf("filename parameter is blank")
shared.SendDocumentServerRespose(w, true)
return
}
fileUrl := srv.StorageManager.GenerateFilestoreUri(filename, managers.FileMeta{
Version: version,
DestinationPath: file,
})
if fileUrl == "" {
srv.logger.Errorf("file url is blank")
shared.SendDocumentServerRespose(w, true)
return
}
http.Redirect(w, r, fileUrl, http.StatusSeeOther)
}

View File

@ -0,0 +1,51 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) HistoryObj(w http.ResponseWriter, r *http.Request) {
var body map[string]string
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("HistoryObj body decoding error")
shared.SendCustomErrorResponse(w, err.Error())
return
}
fileName := body["fileName"]
if fileName == "" {
srv.logger.Error("No filename in historyObj request")
shared.SendCustomErrorResponse(w, "No filename")
return
}
remoteAddr := generateUrl(r)
refHist, setHist, err := srv.Managers.HistoryManager.GetHistory(fileName, remoteAddr)
if err != nil {
srv.logger.Warnf("could not get file history: %s", err.Error())
shared.SendCustomErrorResponse(w, err.Error())
}
refHist.HistoryData = setHist
shared.SendResponse(w, refHist)
}

View File

@ -0,0 +1,42 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"net/http"
)
func (srv *DefaultServerEndpointsHandler) Index(w http.ResponseWriter, r *http.Request) {
srv.logger.Debug("A new index call")
files, err := srv.Managers.StorageManager.GetStoredFiles(r.Host)
if err != nil {
srv.logger.Errorf("could not fetch files: %s", err.Error())
}
data := map[string]interface{}{
"Extensions": srv.specification.Extensions,
"Users": srv.Managers.UserManager.GetUsers(),
"Files": files,
"Preloader": srv.config.DocumentServerHost + srv.config.DocumentServerPreloader,
"ForgottenEnabled": srv.config.ForgottenEnabled,
"Languages": srv.config.Languages,
"ServerVersion": srv.config.Version,
}
indexTemplate.Execute(w, data) // nolint: errcheck
}

View File

@ -0,0 +1,24 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import "go.uber.org/fx"
var DefaultServerEndpointsHandlerModule = fx.Options(
fx.Provide(NewDefaultServerEndpointsHandler),
)

View File

@ -0,0 +1,111 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Reference(w http.ResponseWriter, r *http.Request) {
var body models.Reference
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("Reference body decoding error")
shared.SendDocumentServerRespose(w, true)
return
}
remoteAddr := generateUrl(r)
var fileName /*, userAddress*/ string
var fileKey map[string]string
err := json.Unmarshal([]byte(body.ReferenceData.FileKey), &fileKey)
if err != nil {
srv.logger.Error("FileKey decoding error")
shared.SendDocumentServerRespose(w, true)
return
}
path, _ := srv.GenerateFilePath(fileKey["fileName"])
if body.ReferenceData.InstanceId == remoteAddr && srv.PathExists(path) {
fileName = fileKey["fileName"]
}
if fileName == "" && body.Link != "" {
if strings.Contains(body.Link, remoteAddr) {
res := map[string]interface{}{
"url": body.Link,
}
shared.SendResponse(w, res)
return
}
urlObj, _ := url.Parse(body.Link)
params, _ := url.ParseQuery(urlObj.RawQuery)
if len(params["filename"]) != 0 {
fileName = params["filename"][0]
}
path, _ := srv.GenerateFilePath(fileName)
if !srv.PathExists(path) {
shared.SendCustomErrorResponse(w, "File is not exist")
return
}
}
if fileName == "" && body.Path != "" {
filePath := utils.GetFileName(body.Path)
path, _ := srv.GenerateFilePath(filePath)
if srv.PathExists(path) {
fileName = filePath
}
}
if fileName == "" {
shared.SendCustomErrorResponse(w, "File is not found")
return
}
docKey, _ := srv.GenerateFileHash(fileName)
data := models.Reference{
FileType: srv.GetFileType(fileName),
Key: docKey,
Url: srv.GeneratePublicFileUri(fileName, remoteAddr, managers.FileMeta{}),
ReferenceData: models.ReferenceData{
FileKey: fmt.Sprintf("{\"fileName\":\"%s\"}", fileName),
InstanceId: remoteAddr,
},
Link: remoteAddr + "/editor?filename=" + url.QueryEscape(fileName),
Path: fileName,
}
secret := strings.TrimSpace(srv.config.JwtSecret)
if secret != "" && srv.config.JwtEnabled {
token, _ := srv.JwtSign(data, []byte(secret))
data.Token = token
}
shared.SendResponse(w, data)
}

View File

@ -0,0 +1,54 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Remove(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodDelete {
if err := srv.StorageManager.RemoveAll(); err != nil {
shared.SendDocumentServerRespose(w, true)
return
}
r := map[string]interface{}{
"success": true,
}
shared.SendResponse(w, r)
return
}
filename := r.URL.Query().Get("filename")
if filename == "" {
shared.SendDocumentServerRespose(w, true)
return
}
if err := srv.StorageManager.RemoveFile(filename); err != nil {
srv.logger.Error(err.Error())
shared.SendDocumentServerRespose(w, true)
return
}
srv.logger.Debug("A new remove call")
shared.SendDocumentServerRespose(w, false)
}

View File

@ -0,0 +1,68 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"encoding/json"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Rename(w http.ResponseWriter, r *http.Request) {
var body map[string]string
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("Rename body decoding error")
shared.SendCustomErrorResponse(w, err.Error())
return
}
newFileName, ext, docKey := body["newfilename"], body["ext"], body["dockey"]
if newFileName == "" || docKey == "" {
srv.logger.Error("No filename or dockey")
shared.SendCustomErrorResponse(w, "No filename or dockey")
return
}
if curExt := utils.GetFileExt(newFileName, true); curExt != ext {
newFileName += "." + ext
}
meta := map[string]string{
"title": newFileName,
}
commandResponse, err := srv.CommandManager.CommandRequest("meta", docKey, meta)
if err != nil {
srv.logger.Error("Command request error")
shared.SendCustomErrorResponse(w, err.Error())
return
}
defer commandResponse.Body.Close()
var res map[string]interface{}
if err := json.NewDecoder(commandResponse.Body).Decode(&res); err != nil {
srv.logger.Error("Command response body decoding error")
shared.SendCustomErrorResponse(w, err.Error())
return
}
result := map[string]interface{}{
"result": res,
}
shared.SendResponse(w, result)
}

View File

@ -0,0 +1,110 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"path"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
)
func (srv *DefaultServerEndpointsHandler) Restore(w http.ResponseWriter, r *http.Request) {
result := map[string]interface{}{
"success": false,
}
var body map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
srv.logger.Error("Restore body decoding error")
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
fileName := fmt.Sprintf("%v", body["fileName"])
if fileName == "" {
srv.logger.Error("Restore filename is empty")
result["error"] = "Empty filename"
shared.SendResponse(w, result)
return
}
version := fmt.Sprintf("%v", body["version"])
key, err := srv.GenerateFileHash(fileName)
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
filePath, err := srv.GenerateFilePath(fileName)
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
rootPath, _ := srv.GetRootFolder()
historyPath := path.Join(rootPath, fileName+shared.ONLYOFFICE_HISTORY_POSTFIX)
newVersion := srv.HistoryManager.CountVersion(historyPath)
versionPath := path.Join(historyPath, version, "prev"+utils.GetFileExt(fileName, false))
newVersionPath := path.Join(historyPath, fmt.Sprint(newVersion))
if !srv.Managers.StorageManager.PathExists(versionPath) {
result["error"] = "Version path does not exist"
shared.SendResponse(w, result)
return
}
err = srv.Managers.StorageManager.CreateDirectory(newVersionPath)
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
currFile, _ := srv.Managers.StorageManager.ReadFile(filePath)
err = srv.Managers.StorageManager.CreateFile(
bytes.NewBuffer(currFile),
path.Join(newVersionPath, "prev"+utils.GetFileExt(fileName, false)))
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
err = srv.Managers.StorageManager.CreateFile(bytes.NewBuffer([]byte(key)), path.Join(newVersionPath, "key.txt"))
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
verFile, _ := srv.Managers.StorageManager.ReadFile(versionPath)
err = srv.Managers.StorageManager.CreateFile(bytes.NewBuffer(verFile), filePath)
if err != nil {
result["error"] = err.Error()
shared.SendResponse(w, result)
return
}
result["success"] = true
shared.SendResponse(w, result)
}

View File

@ -0,0 +1,96 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dapi
import (
"fmt"
"net/http"
"time"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
)
func (srv *DefaultServerEndpointsHandler) Upload(w http.ResponseWriter, r *http.Request) {
err := r.ParseMultipartForm(32 << 20)
if err != nil {
srv.logger.Error(err.Error())
return
}
file, handler, err := r.FormFile("uploadedFile")
w.Header().Set("Content-Type", "application/json")
if err != nil {
srv.logger.Error(err.Error())
return
}
srv.logger.Debug("A new upload call")
if !srv.DocumentManager.IsDocumentConvertable(handler.Filename) {
srv.logger.Errorf("File %s is not supported", handler.Filename)
shared.SendCustomErrorResponse(w, "File type is not supported")
return
}
fileName, err := srv.StorageManager.GenerateVersionedFilename(handler.Filename)
if err != nil {
srv.logger.Error(err.Error())
shared.SendCustomErrorResponse(w, err.Error())
return
}
fpath, err := srv.StorageManager.GenerateFilePath(fileName)
if err != nil {
srv.logger.Error(err.Error())
shared.SendCustomErrorResponse(w, err.Error())
return
}
if err = srv.StorageManager.CreateFile(file, fpath); err != nil {
srv.logger.Error(err.Error())
shared.SendCustomErrorResponse(w, err.Error())
return
}
_, uid := shared.GetCookiesInfo(r.Cookies())
user, err := srv.UserManager.GetUserById(uid)
if err != nil {
srv.logger.Errorf("could not find user with id: %s", uid)
shared.SendCustomErrorResponse(w, err.Error())
return
}
err = srv.HistoryManager.CreateMeta(fileName, models.History{
ServerVersion: srv.config.Version,
Changes: []models.Changes{
{
Created: time.Now().UTC().Format("2006-02-1 15:04:05"),
User: models.User{
Id: user.Id,
Username: user.Username,
},
},
},
})
if err != nil {
srv.logger.Errorf("could not create meta")
}
fmt.Fprintf(w, "{\"filename\":\"%s\"}", fileName)
}

View File

@ -0,0 +1,56 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package config
import (
"context"
"github.com/ONLYOFFICE/document-server-integration/server"
"go.uber.org/fx"
"go.uber.org/zap"
)
func Initialize(
lifecycle fx.Lifecycle,
server *server.Server,
logger *zap.SugaredLogger,
) {
lifecycle.Append(
fx.Hook{
OnStart: func(c context.Context) error {
go server.Run()
logger.Infof("Go server is up")
return nil
},
OnStop: func(c context.Context) error {
logger.Info("Shutting down the server")
err := logger.Sync()
if err != nil {
return err
}
err = server.Http.Shutdown(c)
if err != nil {
return err
}
return nil
},
},
)
}

View File

@ -0,0 +1,68 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package handlers
import (
"sync"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"go.uber.org/zap"
)
type CallbackHandler interface {
GetCode() int
Handle(body *models.Callback) error
}
type CallbackRegistry struct {
Locker *sync.Mutex
logger *zap.SugaredLogger
CallbackHandlers map[int]CallbackHandler
}
func New(logger *zap.SugaredLogger) *CallbackRegistry {
reg := &CallbackRegistry{
Locker: &sync.Mutex{},
logger: logger,
CallbackHandlers: make(map[int]CallbackHandler),
}
return reg
}
func (cr *CallbackRegistry) RegisterCallbackHandler(chandler CallbackHandler) error {
if _, exists := cr.CallbackHandlers[chandler.GetCode()]; exists {
return &HandlerExistsError{
Code: chandler.GetCode(),
}
}
cr.CallbackHandlers[chandler.GetCode()] = chandler
return nil
}
func (cr *CallbackRegistry) HandleIncomingCode(cbody *models.Callback) error {
for _, handler := range cr.CallbackHandlers {
if handler.GetCode() == cbody.Status {
cr.logger.Debugf("Processing an incoming callback request with code %d", cbody.Status)
if err := handler.Handle(cbody); err != nil {
return err
}
}
}
return nil
}

View File

@ -0,0 +1,59 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dhandlers
import (
"github.com/ONLYOFFICE/document-server-integration/server/handlers"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"go.uber.org/zap"
)
type DefaultSavingErrorHandler struct {
logger *zap.SugaredLogger
managers.StorageManager
reg *handlers.CallbackRegistry
}
func NewDefaultSavingErrorHandler(
logger *zap.SugaredLogger,
smanager managers.StorageManager,
reg *handlers.CallbackRegistry,
) *DefaultSavingErrorHandler {
shandler := DefaultSavingErrorHandler{
logger,
smanager,
reg,
}
shandler.reg.RegisterCallbackHandler(shandler) // nolint: errcheck
return &shandler
}
func (sh DefaultSavingErrorHandler) GetCode() int {
return 3
}
func (sh DefaultSavingErrorHandler) Handle(cbody *models.Callback) error {
sh.logger.Debugf("Trying to save %s with callback status 3", cbody.Filename)
if err := sh.StorageManager.SaveFileFromUri(*cbody); err != nil {
return err
}
sh.logger.Debugf("Saved %s successfully", cbody.Filename)
return nil
}

View File

@ -0,0 +1,26 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dhandlers
import "go.uber.org/fx"
var DefaultHandlersModule = fx.Options(
fx.Invoke(NewDefaultSaveHandler),
fx.Invoke(NewDefaultSavingErrorHandler),
fx.Invoke(NewDefaultNoChangesHandler),
)

View File

@ -0,0 +1,47 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dhandlers
import (
"github.com/ONLYOFFICE/document-server-integration/server/handlers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"go.uber.org/zap"
)
type DefaultNoChangesHandler struct {
logger *zap.SugaredLogger
reg *handlers.CallbackRegistry
}
func NewDefaultNoChangesHandler(logger *zap.SugaredLogger, reg *handlers.CallbackRegistry) *DefaultNoChangesHandler {
handler := DefaultNoChangesHandler{
logger,
reg,
}
handler.reg.RegisterCallbackHandler(handler) // nolint: errcheck
return &handler
}
func (nh DefaultNoChangesHandler) GetCode() int {
return 4
}
func (nh DefaultNoChangesHandler) Handle(cbody *models.Callback) error {
nh.logger.Debugf("No %s changes", cbody.Filename)
return nil
}

View File

@ -0,0 +1,62 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dhandlers
import (
"github.com/ONLYOFFICE/document-server-integration/server/handlers"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"go.uber.org/zap"
)
type DefaultSaveHandler struct {
logger *zap.SugaredLogger
managers.StorageManager
managers.HistoryManager
reg *handlers.CallbackRegistry
}
func NewDefaultSaveHandler(logger *zap.SugaredLogger, smanager managers.StorageManager,
hmanager managers.HistoryManager, reg *handlers.CallbackRegistry) *DefaultSaveHandler {
shandler := DefaultSaveHandler{
logger,
smanager,
hmanager,
reg,
}
shandler.reg.RegisterCallbackHandler(shandler) // nolint: errcheck
return &shandler
}
func (sh DefaultSaveHandler) GetCode() int {
return 2
}
func (sh DefaultSaveHandler) Handle(cbody *models.Callback) error {
sh.logger.Debugf("Trying to save %s", cbody.Filename)
if err := sh.HistoryManager.CreateHistory(*cbody); err != nil {
return err
}
if err := sh.StorageManager.SaveFileFromUri(*cbody); err != nil {
return err
}
sh.logger.Debugf("Saved %s successfully", cbody.Filename)
return nil
}

View File

@ -0,0 +1,28 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package handlers
import "fmt"
type HandlerExistsError struct {
Code int
}
func (e *HandlerExistsError) Error() string {
return fmt.Sprintf("A Handler with code %d exists", e.Code)
}

View File

@ -0,0 +1,35 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package log
import (
"github.com/ONLYOFFICE/document-server-integration/config"
"go.uber.org/zap"
)
func New(config config.ApplicationConfig) *zap.SugaredLogger {
var logger *zap.Logger
if config.LoggerDebug {
logger, _ = zap.NewDevelopment()
} else {
logger, _ = zap.NewProduction()
}
sugarLogger := logger.Sugar()
return sugarLogger
}

View File

@ -0,0 +1,26 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package log
import (
"go.uber.org/fx"
)
var LoggingModule = fx.Options(
fx.Provide(New),
)

View File

@ -0,0 +1,110 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package managers
import (
"io"
"net/http"
"github.com/ONLYOFFICE/document-server-integration/server/models"
"github.com/golang-jwt/jwt"
)
type DocumentManager interface {
BuildDocumentConfig(parameters Editor, storageAddress string) (*models.Config, error)
IsDocumentConvertable(filename string) bool
}
type HistoryManager interface {
GetHistory(filename, storageAddress string) (HistoryRefresh, []HistorySet, error)
CreateMeta(filename string, history models.History) error
CreateHistory(cbody models.Callback) error
CountVersion(directory string) int
GetFileData(filename string) map[string]string
}
type StorageManager interface {
GetRootFolder() (string, error)
GenerateFilePath(filename string) (string, error)
GetStoredFiles(storageAddress string) ([]models.Document, error)
GenerateFileHash(filename string) (string, error)
GenerateFilestoreUri(originalName string, meta FileMeta) string
GeneratePublicFileUri(originalName, storageAddress string, meta FileMeta) string
GenerateVersionedFilename(filename string) (string, error)
CreateFile(stream io.Reader, path string) error
CreateDirectory(path string) error
PathExists(path string) bool
DirExists(path string) bool
RemoveFile(filename string) error
RemoveAll() error
ReadFile(filePath string) ([]byte, error)
MoveFile(from, to string) error
SaveFileFromUri(body models.Callback) error
}
type UserManager interface {
GetUsers() []models.User
GetUserById(uid string) (models.User, error)
GetUserInfoById(uid string, serverAddress string) models.UserInfo
GetUsersForMentions(uid string) []models.UserInfo
GetUsersForProtect(uid string, serverAddress string) []models.UserInfo
GetUsersInfo(serverAddress string) []models.UserInfo
}
type JwtManager interface {
JwtSign(claims jwt.Claims, key []byte) (string, error)
JwtDecode(jwtString string, key []byte) (jwt.MapClaims, error)
ParseCallback(body *models.Callback, tokenHeader string) error
}
type ConversionManager interface {
GetFileType(filename string) string
GetInternalExtension(fileType string) string
IsCanConvert(ext string) bool
IsCanFill(ext string) bool
GetConverterUri(docUri, fromExt, toExt, docKey string, isAsync bool) (string, string, error)
}
type CommandManager interface {
CommandRequest(method string, docKey string, meta interface{}) (*http.Response, error)
}
type Managers struct {
DocumentManager
HistoryManager
StorageManager
UserManager
JwtManager
ConversionManager
CommandManager
}
func New(umanager UserManager, smanager StorageManager,
hmanager HistoryManager, dmanager DocumentManager,
jmanager JwtManager, cmanager ConversionManager,
commanager CommandManager) *Managers {
return &Managers{
HistoryManager: hmanager,
StorageManager: smanager,
DocumentManager: dmanager,
UserManager: umanager,
JwtManager: jmanager,
ConversionManager: cmanager,
CommandManager: commanager,
}
}

View File

@ -0,0 +1,118 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dmanager
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
"strings"
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/golang-jwt/jwt"
)
type DefaultCommandManager struct {
config config.ApplicationConfig
managers.JwtManager
}
type CommandPayload struct {
C string `json:"c"`
Key string `json:"key"`
Meta interface{} `json:"meta"`
Token string `json:"token"`
jwt.StandardClaims
}
type CommandRequestHeaderPayload struct {
Query map[string]string `json:"query"`
Payload CommandPayload `json:"payload"`
jwt.StandardClaims
}
func NewDefaultCommandManager(config config.ApplicationConfig, jmanager managers.JwtManager) managers.CommandManager {
return &DefaultCommandManager{
config,
jmanager,
}
}
func (cm DefaultCommandManager) CommandRequest(method string, docKey string, meta interface{}) (*http.Response, error) {
payload := CommandPayload{
C: method,
Key: docKey,
}
if meta != nil {
payload.Meta = meta
}
uri := cm.config.DocumentServerHost + cm.config.DocumentServerCommandUrl
var err error
var headerToken string
secret := strings.TrimSpace(cm.config.JwtSecret)
if secret != "" && cm.config.JwtEnabled {
headerPayload := fillJwtByUrl(uri, payload)
headerToken, err = cm.JwtManager.JwtSign(headerPayload, []byte(secret))
if err != nil {
return nil, err
}
payload.Token, err = cm.JwtManager.JwtSign(payload, []byte(secret))
if err != nil {
return nil, err
}
}
requestBody, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, uri, bytes.NewReader(requestBody))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
if headerToken != "" {
req.Header.Set(cm.config.JwtHeader, "Bearer "+headerToken)
}
response, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
return response, nil
}
func fillJwtByUrl(uri string, payload CommandPayload) CommandRequestHeaderPayload {
urlObj, _ := url.Parse(uri)
query, _ := url.ParseQuery(urlObj.RawQuery)
queryMap := make(map[string]string)
for k, v := range query {
queryMap[k] = v[0]
}
return CommandRequestHeaderPayload{
Query: queryMap,
Payload: payload,
}
}

View File

@ -0,0 +1,178 @@
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package dmanager
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"github.com/ONLYOFFICE/document-server-integration/config"
"github.com/ONLYOFFICE/document-server-integration/server/managers"
"github.com/ONLYOFFICE/document-server-integration/server/shared"
"github.com/ONLYOFFICE/document-server-integration/utils"
"go.uber.org/zap"
)
type DefaultConversionManager struct {
config config.ApplicationConfig
specification config.SpecificationConfig
logger *zap.SugaredLogger
managers.JwtManager
}
func NewDefaultConversionManager(config config.ApplicationConfig, spec config.SpecificationConfig,
logger *zap.SugaredLogger, jmanager managers.JwtManager) managers.ConversionManager {
return &DefaultConversionManager{
config,
spec,
logger,
jmanager,
}
}
func (cm DefaultConversionManager) GetFileType(filename string) string {
ext := utils.GetFileExt(filename, true)
exts := cm.specification.ExtensionTypes
if utils.IsInList(ext, exts.Pdf) {
return shared.ONLYOFFICE_PDF
}
if utils.IsInList(ext, exts.Document) {
return shared.ONLYOFFICE_DOCUMENT
}
if utils.IsInList(ext, exts.Spreadsheet) {
return shared.ONLYOFFICE_SPREADSHEET
}
if utils.IsInList(ext, exts.Presentation) {
return shared.ONLYOFFICE_PRESENTATION
}
return shared.ONLYOFFICE_DOCUMENT
}
func (cm DefaultConversionManager) GetInternalExtension(fileType string) string {
switch fileType {
case shared.ONLYOFFICE_DOCUMENT:
return ".docx"
case shared.ONLYOFFICE_SPREADSHEET:
return ".xlsx"
case shared.ONLYOFFICE_PRESENTATION:
return ".pptx"
default:
return ".docx"
}
}
func (cm DefaultConversionManager) IsCanFill(ext string) bool {
return utils.IsInList(ext, cm.specification.Extensions.Filled)
}
func (cm DefaultConversionManager) IsCanConvert(ext string) bool {
return utils.IsInList(ext, cm.specification.Extensions.Converted)
}
func (cm DefaultConversionManager) GetConverterUri(
docUri string,
fromExt string,
toExt string,
docKey string,
isAsync bool,
) (string, string, error) {
if fromExt == "" {
fromExt = utils.GetFileExt(docUri, true)
}
payload := managers.ConvertRequestPayload{
DocUrl: docUri,
OutputType: strings.ReplaceAll(toExt, ".", ""),
FileType: fromExt,
Title: utils.GetFileName(docUri),
Key: docKey,
Async: isAsync,
}
var headerToken string
var err error
secret := strings.TrimSpace(cm.config.JwtSecret)
if secret != "" && cm.config.JwtEnabled {
headerPayload := managers.ConvertRequestHeaderPayload{Payload: payload}
headerToken, err = cm.JwtManager.JwtSign(headerPayload, []byte(secret))
if err != nil {
return "", "", err
}
bodyToken, err := cm.JwtManager.JwtSign(payload, []byte(secret))
if err != nil {
return "", "", err
}
payload.JwtToken = bodyToken
}
requestBody, err := json.Marshal(payload)
if err != nil {
return "", "", err
}
req, err := http.NewRequest(
http.MethodPost,
cm.config.DocumentServerHost+cm.config.DocumentServerConverter,
bytes.NewReader(requestBody),
)
if err != nil {
return "", "", err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
if headerToken != "" {
req.Header.Set(cm.config.JwtHeader, "Bearer "+headerToken)
}
response, err := http.DefaultClient.Do(req)
if err != nil {
return "", "", err
}
defer response.Body.Close()
jsonBody, err := io.ReadAll(response.Body)
if err != nil {
return "", "", err
}
var body managers.ConvertPayload
if err := json.Unmarshal(jsonBody, &body); err != nil {
return "", "", err
}
return getResponseUri(body)
}
func getResponseUri(json managers.ConvertPayload) (string, string, error) {
if json.Error < 0 {
return "", "", fmt.Errorf("error occurred in the ConvertService: %d", json.Error)
}
return json.FileUrl, json.FileType, nil
}

Some files were not shown because too many files have changed in this diff Show More