gist/README.md

389 lines
10 KiB
Markdown
Raw Normal View History

2016-09-19 13:08:18 +02:00
Table of Contents
=================
* [GIST](#gist)
* [Requirements](#requirements)
* [Git](#git)
* [Composer](#composer)
2018-08-08 12:41:08 +02:00
* [NPM](#npm)
2016-09-28 00:43:54 +02:00
* [Installation](#installation)
* [Upgrade](#upgrade)
2017-04-24 01:11:54 +02:00
* [Configuration](#configuration)
2016-09-19 13:08:18 +02:00
* [Makefile](#makefile)
* [API](#api)
* [Console](#console)
* [Deployment](#deployment)
2016-10-03 17:41:01 +02:00
* [Contributors](#contributors)
2016-09-19 13:08:18 +02:00
2017-04-24 01:11:54 +02:00
2015-05-06 10:58:55 +02:00
GIST
====
GIST is an open-source application to share code.
2015-05-10 02:32:24 +02:00
https://www.deblan.io/post/517/gist-est-dans-la-place
2015-05-06 10:58:55 +02:00
2015-11-30 01:09:59 +01:00
![Gist](https://upload.deblan.org/u/2015-11/565b93a5.png "Gist")
2015-05-12 11:13:30 +02:00
![Gist](https://upload.deblan.org/u/2016-06/57655dec.png "Gist")
2017-04-24 01:11:54 +02:00
2015-05-06 10:58:55 +02:00
Requirements
------------
2018-08-20 12:50:58 +02:00
* PHP >= 5.4 with PDO
2015-05-06 10:58:55 +02:00
* GIT
2018-08-20 12:50:58 +02:00
* MySQL or SQLite (PostgreSQL should work)
2015-05-06 11:04:38 +02:00
* Composer (php)
2018-08-08 12:41:08 +02:00
* NPM (nodejs)
2015-05-06 10:58:55 +02:00
2016-09-28 00:43:54 +02:00
### Git
Git can maybe be downloaded from your system's repositories.
2018-08-08 09:37:19 +02:00
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
2016-09-28 00:43:54 +02:00
### Composer
Composer can maybe be downloaded from your system's repositories.
Else, follow the next instructions:
2018-08-08 09:37:19 +02:00
# With cURL
$ curl -sS https://getcomposer.org/installer | php
2016-09-28 00:43:54 +02:00
2018-08-08 09:37:19 +02:00
# With Wget
$ wget -O - -q https://getcomposer.org/installer | php
2016-09-28 00:43:54 +02:00
2018-08-08 09:37:19 +02:00
$ chmod +x composer.phar
2016-09-28 00:43:54 +02:00
2018-08-08 09:37:19 +02:00
# For a local installation and if the envvar PATH contains "$HOME/bin/"
$ mv composer.phar ~/bin/composer
2016-10-02 20:31:08 +02:00
2018-08-08 09:37:19 +02:00
# For a global installation
$ sudo mv composer.phar /usr/local/bin/composer
2016-09-28 00:43:54 +02:00
2018-08-08 12:41:08 +02:00
### NPM
2016-09-28 00:43:54 +02:00
2018-08-20 12:50:58 +02:00
$ sudo apt install npm
2016-09-28 00:43:54 +02:00
2015-05-06 10:58:55 +02:00
Installation
------------
2018-08-08 09:37:19 +02:00
$ cd /path/to/www/
$ git clone https://gitnet.fr/deblan/gist
$ cd gist
$ make
2016-12-23 11:23:58 +01:00
2018-08-20 12:50:58 +02:00
An interactive shell will start. If you want to run the interactive shell manually, run:
2016-09-28 00:25:47 +02:00
2018-08-20 12:50:58 +02:00
$ composer gist-scripts
2016-09-28 00:25:47 +02:00
2018-08-20 12:50:58 +02:00
To perform a manual configuration, follow these instructions.
2016-12-23 11:23:58 +01:00
2018-08-20 12:50:58 +02:00
With `MySQL`:
2016-09-28 00:25:47 +02:00
2018-08-20 12:50:58 +02:00
$ cp app/config/propel.yaml.dist-mysql propel.yaml
2016-09-28 00:25:47 +02:00
2018-08-20 12:50:58 +02:00
With `SQLite`:
2015-05-09 17:42:53 +02:00
2018-08-20 12:50:58 +02:00
$ cp app/config/propel.yaml.dist-sqlite propel.yaml
2018-08-20 12:33:49 +02:00
2018-08-20 12:50:58 +02:00
Then edit `propel.yaml` and replace the values of `dsn`, `user`, `password` by considering your environment and run `$ make propel`.
2018-08-20 12:33:49 +02:00
2017-04-24 01:11:54 +02:00
**Versions >= 1.4.4 only**: `$ cp app/config/config.yml.dist app/config/config.yml`
See the [configuration section](#configuration) for more information about configuration.
---
2015-05-06 10:58:55 +02:00
2016-10-02 20:31:08 +02:00
The web server must have permission to write into `data`.
2018-08-08 09:37:19 +02:00
$ sudo chown -R www-data:www-data data
2016-10-02 20:31:08 +02:00
2016-10-03 23:32:01 +02:00
Your webserver must be configured to serve `web/` as document root. If you use nginx, all virtual paths must be rooted with `web/index.php` or `web/app_dev.php` ([documentation](https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/)). If you use apache, you must enable the `rewrite` module and restart:
2018-08-08 09:37:19 +02:00
$ sudo a2enmod rewrite
$ sudo service apache2 restart
2016-10-03 23:29:49 +02:00
2017-04-24 01:11:54 +02:00
`app_dev.php` is the development router. Access is granted for an IP range defined in the same file.
2016-09-28 00:43:54 +02:00
Upgrade
-------
2016-12-23 11:23:58 +01:00
If your version is less than v1.4.2, run: `test -d app && git add app && git commit -m "Configuration"`.
2018-08-08 09:37:19 +02:00
$ make update
$ make propel
2015-11-24 19:26:58 +01:00
2018-08-20 12:50:58 +02:00
If you upgrade from <= v1.4.0 to >= v1.4.1: `app/console migrate:to:v1.4.1`.
2016-12-23 11:23:58 +01:00
2018-08-20 12:50:58 +02:00
If you upgrade from <= v1.4.3 to >= v1.4.4, the configuration is moved to `app/config/config.yml`: `$ cp app/config/config.yml.dist app/config/config.yml` and see the [configuration section](#configuration) for more information.
2017-04-24 01:11:54 +02:00
2017-09-21 18:45:45 +02:00
If you upgrade to v1.7.0 or more, see the [configuration section](#configurationh) for more information about new options.
2017-04-24 01:11:54 +02:00
Configuration
-------------
### Version < 1.4.4
Edit `app/bootstrap.php.d/70-security.php`.
* `$app['token']`: the securty token (a strong passphrase).
* `$app['enable_registration']`: defines if the registration is allowed (`true` or `false`)
* `$app['enable_login']`: defines if the login is allowed (`true` or `false`)
* `$app['login_required_to_edit_gist']`: defines if the user must be logged to create or clone a Gist (`true` or `false`)
* `$app['login_required_to_view_gist']`: defines if the user must be logged to view a Gist (`true` or `false`)
* `$app['login_required_to_view_gist']`: defines if the user must be logged to view an embeded Gist (`true` or `false`)
If you install Gist on your server, you have to modify the `base_uri` of the API.
Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`.
### Version >= 1.4.4
Edit `app/config/config.yml`.
* `security.token`: the securty token (a strong passphrase)
* `security.enable_registration`: defines if the registration is allowed (`true` or `false`)
* `security.enable_login`: defines if the login is allowed (`true` or `false`)
* `security.login_required_to_edit_gist`: defines if the user must be logged to create or clone a Gist (`true` or `false`)
* `security.login_required_to_view_gist`: defines if the user must be logged to view a Gist (`true` or `false`)
* `security.login_required_to_view_gist`: defines if the user must be logged to view an embeded Gist (`true` or `false`)
* `api.base_uri`: The url of your instance.
* `data.path`: the path where the files are saved.
* `git.path`: The path of `git`.
2017-04-24 01:18:21 +02:00
* `theme.name`: the name of the theme (`dark` or `light`)
2017-04-24 01:11:54 +02:00
2017-09-21 18:45:45 +02:00
### Version >= v1.7.0
* `api.enabled`: defines if the API is enabled (`true` or `false`)
* `api.api_key_required`: defines if the API key is required to access the API (`true` or `false`)
* `api.client.api_key`: defines the client API key (`string`)
2015-05-06 10:58:55 +02:00
Makefile
--------
A Makefile is provided to automate some tasks.
2018-08-08 12:41:08 +02:00
* `make` will install dependencies via composer and NPM
* `make composer` will install PHP dependencies via composer
* `make npm` will install CSS/JS dependencies via NPM
2015-05-09 17:42:53 +02:00
* `make update` will update the application
2018-08-08 12:41:08 +02:00
* `make propel` will generate propel migrations (database and files)
2015-09-17 11:41:32 +02:00
* `make run` will run development server on http://127.0.0.1:8080/
2015-07-19 18:39:46 +02:00
2018-08-08 12:41:08 +02:00
By default, `composer`, `npm`, `git`, `mkdir` and `php` binaries must be in your `$PATH`. You can override it by using these envars:
* `COMPOSER`
* `NPM`
* `GIT`
* `MKDIR`
* `PHP`
For example:
$ export COMPOSER=/path/to/composer
$ make composer
2015-07-19 18:39:46 +02:00
API
---
2017-09-21 18:45:45 +02:00
### Version < v1.7.0
#### Create a new gist
2015-07-19 18:39:46 +02:00
**POST** /{locale}/api/create
Params:
2016-09-28 00:43:54 +02:00
* `form[title]`: String (required, can be empty)
* `form[type]`: String (required)
2015-07-19 18:39:46 +02:00
Values: html, css, javascript, php, sql, xml, yaml, perl, c, asp, python, bash, actionscript3, text
2016-09-28 00:43:54 +02:00
* `form[content]`: String (required)
2015-07-19 18:39:46 +02:00
2016-09-28 00:43:54 +02:00
**Responses:**
2015-07-19 18:39:46 +02:00
2017-04-24 01:11:54 +02:00
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
2016-09-28 00:43:54 +02:00
* Code `200`: A json which contains gist's information. Example:
2017-04-24 01:11:54 +02:00
```javascript
2015-07-19 18:42:22 +02:00
{
2015-09-17 11:41:32 +02:00
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
2015-07-19 18:42:22 +02:00
"gist": {
2015-09-17 11:48:52 +02:00
"Id": 66,
2015-07-19 18:42:22 +02:00
"Title": "test prod",
"Cipher": false,
"Type": "javascript",
"File": "55abcfa7771e0",
"CreatedAt": "2015-07-19T16:26:15Z",
"UpdatedAt": "2015-07-19T16:26:15Z"
}
}
2017-04-24 01:11:54 +02:00
```
2015-07-19 18:39:46 +02:00
2017-09-21 18:45:45 +02:00
#### Update an existing gist
2015-11-07 22:13:08 +01:00
**POST** /{locale}/api/update/{id}
Params:
2016-09-28 00:43:54 +02:00
* `{id}`: Gist Id (required)
* `form[content]`: String (required)
2015-11-07 22:13:08 +01:00
2016-09-28 00:43:54 +02:00
**Responses:**
2015-11-07 22:13:08 +01:00
2017-04-24 01:11:54 +02:00
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
2016-09-28 00:43:54 +02:00
* Code `200`: A json which contains gist's information. Example:
2017-04-24 01:11:54 +02:00
```javascript
2015-11-07 22:13:08 +01:00
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
"gist": {
"Id": 66,
"Title": "test prod",
"Cipher": false,
"Type": "javascript",
"File": "55abcfa7771e0",
"CreatedAt": "2015-07-19T16:26:15Z",
"UpdatedAt": "2015-07-19T16:30:15Z"
}
}
2017-04-24 01:11:54 +02:00
```
2015-11-07 22:13:08 +01:00
2017-09-21 18:45:45 +02:00
### Version >= v1.7.0
Invalid response codes:
* Code `401`: Unauthorized
* Code `403`: API not enabled
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
#### List gists
**GET** /{locale}/api/list/{apiToken}
Response example:
```javascript
[
{
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:30:15Z"
2018-08-08 09:37:19 +02:00
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
2017-09-21 18:45:45 +02:00
},
{
"id": 67,
"title": "test prod 2",
"cipher": false,
"type": "javascript",
"file": "xyzbcfa7771e0",
"createdAt": "2015-08-19T16:26:15Z",
"updatedAt": "2015-08-19T16:30:15Z"
2018-08-08 09:37:19 +02:00
"url": "https:\/\/gist.deblan.org\/en\/view\/5byzbcfa7771e0\/def72967dd95e346koq0dcaa310d728d6artu",
2017-09-21 18:45:45 +02:00
},
2018-08-08 09:37:19 +02:00
...
2017-09-21 18:45:45 +02:00
]
```
#### Create a new gist
**POST** /{locale}/api/create/{apiToken}
Params:
* `form[title]`: String (required, can be empty)
* `form[type]`: String (required)
Values: html, css, javascript, php, sql, xml, yaml, perl, c, asp, python, bash, actionscript3, text
* `form[content]`: String (required)
Response example:
```javascript
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
"gist": {
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:26:15Z"
}
}
```
#### Update an existing gist
**POST** /{locale}/api/update/{id}/{apiToken}
Params:
* `{id}`: Gist Id (required)
* `form[content]`: String (required)
Response example:
```javascript
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
"gist": {
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:30:15Z"
}
}
```
#### Delete an existing gist
**POST** /{locale}/api/delete/{id}/{apiToken}
Response code `200`:
```javascript
{"error":false}
```
Response code `400`:
```javascript
{"message":"Invalid Gist", "error":true}
```
2015-07-19 18:45:01 +02:00
Console
-------
2017-04-24 01:11:54 +02:00
* **Create a gist**: `$ app/console --help create`
* **Update a gist**: `$ app/console --help update`
2018-08-20 12:34:47 +02:00
* **Create user**: `$ app/console --help user:create`
2017-04-24 01:11:54 +02:00
* **Show stats**: `$ app/console --help stats`
2016-02-02 19:31:22 +01:00
2017-09-21 18:45:45 +02:00
### Version >= v1.7.0
* **List your gists**: `$ app/console --help gists`
* **Delete a gist**: `$ app/console --help delete`
2016-10-03 17:41:01 +02:00
Contributors
------------
**Developers**
2016-10-03 23:35:26 +02:00
* Simon Vieille <contact@deblan.fr>
2016-10-03 17:41:01 +02:00
2016-10-03 19:10:34 +02:00
**Translators**
2016-10-03 17:41:01 +02:00
2016-10-03 23:35:26 +02:00
* Simon Vieille <contact@deblan.fr>
* Marion Sanchez
* Marjorie Da Silva
2016-12-21 22:55:06 +01:00
* Mélanie Chanat
2017-06-04 17:31:55 +02:00
* Showfom
2018-04-12 09:19:12 +02:00
* Tavin