Skip to content

Commit

Permalink
Merge branch 'release/6.0.5'
Browse files Browse the repository at this point in the history
* release/6.0.5:
  compile assets
  Apply fixes from StyleCI (#856)
  adding tests
  fixes #855
  Apply fixes from StyleCI (#854)
  refactor to service class
  Apply fixes from StyleCI (#853)
  cleanup and refactoring
  Apply fixes from StyleCI (#852)
  command cleanup
  specify devDependencies
  route updates for Laravel 8
  • Loading branch information
austintoddj committed Oct 4, 2020
2 parents 0d0db9f + fce36cf commit 3c562a5
Show file tree
Hide file tree
Showing 39 changed files with 742 additions and 748 deletions.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@
},
"dependencies": {
"axios": "^0.20.0",
"babel-eslint": "^10.1.0",
"bootstrap": "^4.5.2",
"chart.js": "^2.9.3",
"cross-env": "^7.0.2",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-sort-imports-es6-autofix": "^0.5.0",
"eslint-plugin-vue": "^6.2.2",
"filepond": "^4.19.2",
"filepond-plugin-file-validate-size": "^2.2.1",
"filepond-plugin-file-validate-type": "^1.2.5",
Expand All @@ -34,7 +27,6 @@
"numeral": "^2.0.6",
"parchment": "^1.1.4",
"popper.js": "^1.16.1",
"prettier": "^2.0.5",
"quill": "1.3.7",
"resolve-url-loader": "^3.1.1",
"sass": "^1.26.11",
Expand All @@ -51,5 +43,15 @@
"vue-textarea-autosize": "^1.1.1",
"vue-toasted": "^1.1.28",
"vuex": "^3.5.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-sort-imports-es6-autofix": "^0.5.0",
"eslint-plugin-vue": "^6.2.2",
"prettier": "^2.0.5"
}
}
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/app.js": "/js/app.js?id=029003d84e5ed3d24c69",
"/js/app.js": "/js/app.js?id=78fb3c1c3f8e654c6623",
"/css/app.css": "/css/app.css?id=275ebb89871e5f9dca7a",
"/js/app.js.map": "/js/app.js.map?id=31898060bcd3393f9abd",
"/js/app.js.map": "/js/app.js.map?id=a5de649d315b6e05ba9f",
"/css/app.css.map": "/css/app.css.map?id=db11b78da46b5c2c6055"
}
4 changes: 2 additions & 2 deletions resources/js/components/PageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export default {
methods: {
logout() {
axios.get(`/${this.settings.path}/logout`).then(() => {
window.location.href = `/${this.settings.path}/login`;
axios.get(`${this.baseDomain}/logout`).then(() => {
window.location.href = `${this.baseDomain}/login`;
});
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/editor/EmbedImageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default {
getServerOptions() {
return {
url: `/${this.settings.path}/api/uploads`,
url: `${this.baseDomain}/api/uploads`,
headers: {
'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content,
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/modals/AvatarModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default {
getServerOptions() {
return {
url: `/${this.settings.path}/api/uploads`,
url: `${this.baseDomain}/api/uploads`,
headers: {
'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content,
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/modals/FeaturedImageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default {
getServerOptions() {
return {
url: `/${this.settings.path}/api/uploads`,
url: `${this.baseDomain}/api/uploads`,
headers: {
'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content,
},
Expand Down
10 changes: 8 additions & 2 deletions resources/js/mixins/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { store } from '../store';
import axios from 'axios';

export default {
computed: {
baseDomain() {
return store.state.settings.domain || `/${store.state.settings.path}`;
},
},

methods: {
request() {
let instance = axios.create();

instance.defaults.headers.common['X-CSRF-TOKEN'] = document.head.querySelector(
'meta[name="csrf-token"]'
).content;
instance.defaults.baseURL = `/${store.state.settings.path}`;
instance.defaults.baseURL = this.baseDomain;

const requestHandler = (request) => {
// Add any request modifiers...
Expand All @@ -21,7 +27,7 @@ export default {
switch (error.response.status) {
case 401:
case 405:
window.location.href = `/${store.state.settings.path}/logout`;
window.location.href = `${this.baseDomain}/logout`;
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions resources/js/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const initialState = {
languageCodes: window.Canvas.languageCodes,
maxUpload: window.Canvas.maxUpload,
path: window.Canvas.path,
domain: window.Canvas.domain,
timezone: window.Canvas.timezone,
unsplash: window.Canvas.unsplash,
user: window.Canvas.user,
Expand Down
4 changes: 4 additions & 0 deletions resources/stubs/webpack.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mix.js('resources/js/canvas-ui/app.js', 'public/js/canvas-ui.js').sass(
'resources/sass/canvas-ui.scss',
'public/css/canvas-ui.css'
);
3 changes: 0 additions & 3 deletions resources/stubs/webpack.stub

This file was deleted.

File renamed without changes.
93 changes: 93 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

use Canvas\Http\Controllers\Auth\ForgotPasswordController;
use Canvas\Http\Controllers\Auth\LoginController;
use Canvas\Http\Controllers\Auth\ResetPasswordController;
use Canvas\Http\Controllers\HomeController;
use Canvas\Http\Controllers\PostController;
use Canvas\Http\Controllers\SearchController;
use Canvas\Http\Controllers\StatsController;
use Canvas\Http\Controllers\TagController;
use Canvas\Http\Controllers\TopicController;
use Canvas\Http\Controllers\UploadsController;
use Canvas\Http\Controllers\UserController;
use Canvas\Http\Middleware\Admin;
use Canvas\Http\Middleware\Authorize;
use Illuminate\Support\Facades\Route;

// Authentication routes...
Route::namespace('Auth')->group(function () {
Route::prefix('login')->group(function () {
Route::get('/', 'LoginController@showLoginForm')->name('canvas.login');
Route::post('/', 'LoginController@login');
});

Route::prefix('password')->group(function () {
Route::get('reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('canvas.password.request');
Route::post('email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('canvas.password.email');
Route::get('reset/{token}', [ResetPasswordController::class, 'showResetForm'])->name('canvas.password.reset');
Route::post('reset', [ResetPasswordController::class, 'reset'])->name('canvas.password.update');
});

Route::get('logout', [LoginController::class, 'logout'])->name('canvas.logout');
});

// API routes...
Route::middleware([Authorize::class])->group(function () {
Route::prefix('api')->group(function () {
Route::prefix('uploads')->group(function () {
Route::post('/', [UploadsController::class, 'store']);
Route::delete('/', [UploadsController::class, 'destroy']);
});

Route::prefix('posts')->group(function () {
Route::get('/', [PostController::class, 'index']);
Route::get('create', [PostController::class, 'create']);
Route::get('{id}', [PostController::class, 'show']);
Route::post('{id}', [PostController::class, 'store']);
Route::delete('{id}', [PostController::class, 'destroy']);
});

Route::prefix('stats')->group(function () {
Route::get('/', [StatsController::class, 'index']);
Route::get('{id}', [StatsController::class, 'show']);
});

Route::prefix('tags')->middleware([Admin::class])->group(function () {
Route::get('/', [TagController::class, 'index']);
Route::get('create', [TagController::class, 'create']);
Route::get('{id}', [TagController::class, 'show']);
Route::get('{id}/posts', [TagController::class, 'showPosts']);
Route::post('{id}', [TagController::class, 'store']);
Route::delete('{id}', [TagController::class, 'destroy']);
});

Route::prefix('topics')->middleware([Admin::class])->group(function () {
Route::get('/', [TopicController::class, 'index']);
Route::get('create', [TopicController::class, 'create']);
Route::get('{id}', [TopicController::class, 'show']);
Route::get('{id}/posts', [TopicController::class, 'showPosts']);
Route::post('{id}', [TopicController::class, 'store']);
Route::delete('{id}', [TopicController::class, 'destroy']);
});

Route::prefix('users')->group(function () {
Route::get('/', [UserController::class, 'index'])->middleware([Admin::class]);
Route::get('create', [UserController::class, 'create'])->middleware([Admin::class]);
Route::get('{id}', [UserController::class, 'show']);
Route::get('{id}/posts', [UserController::class, 'showPosts']);
Route::post('{id}', [UserController::class, 'store']);
Route::delete('{id}', [UserController::class, 'destroy'])->middleware([Admin::class]);
});

Route::prefix('search')->group(function () {
Route::get('posts', [SearchController::class, 'showPosts']);
Route::get('tags', [SearchController::class, 'showTags'])->middleware([Admin::class]);
Route::get('topics', [SearchController::class, 'showTopics'])->middleware([Admin::class]);
Route::get('users', [SearchController::class, 'showUsers'])->middleware([Admin::class]);
});
});

// Catch-all route...
Route::get('/{view?}', [HomeController::class, 'index'])->where('view', '(.*)')->name('canvas');
});
49 changes: 49 additions & 0 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Canvas\Models\User;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use RuntimeException;

class Canvas
Expand Down Expand Up @@ -91,4 +92,52 @@ public static function assetsUpToDate(): bool

return File::get($path) === File::get(__DIR__.'/../public/mix-manifest.json');
}

/**
* Return the configured storage path url.
*
* @return string
*/
public static function baseStoragePath(): string
{
return sprintf('%s/%s', config('canvas.storage_path'), 'images');
}

/**
* Check if a given URL is valid.
*
* @param string|null $url
* @return bool
*/
public static function isValid(?string $url): bool
{
return filter_var($url, FILTER_VALIDATE_URL) ? true : false;
}

/**
* Trim a given URL and return the base.
*
* @param string|null $url
* @return mixed
*/
public static function trim(?string $url)
{
return parse_url($url)['host'] ?? null;
}

/**
* Generate a Gravatar for a given email.
*
* @param string $email
* @param int $size
* @param string $default
* @param string $rating
* @return string
*/
public static function gravatar(string $email, int $size = 200, string $default = 'retro', string $rating = 'g'): string
{
$hash = md5(trim(Str::lower($email)));

return "https://secure.gravatar.com/avatar/{$hash}?s={$size}&d={$default}&r={$rating}";
}
}
12 changes: 6 additions & 6 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function boot()
* @return void
* @throws BindingResolutionException
*/
private function registerEvents()
protected function registerEvents()
{
$events = $this->app->make(Dispatcher::class);

Expand All @@ -76,14 +76,14 @@ private function registerEvents()
*
* @return void
*/
private function configureRoutes()
protected function configureRoutes()
{
Route::namespace('Canvas\Http\Controllers')
->middleware(config('canvas.middleware'))
->domain(config('canvas.domain'))
->prefix(config('canvas.path'))
->group(function () {
$this->loadRoutesFrom(__DIR__.'/Http/routes.php');
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
});
}

Expand All @@ -109,7 +109,7 @@ protected function configureCommands()
*
* @return void
*/
private function registerMigrations()
protected function registerMigrations()
{
if ($this->app->runningInConsole()) {
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
Expand All @@ -121,7 +121,7 @@ private function registerMigrations()
*
* @return void
*/
private function registerAuthDriver()
protected function registerAuthDriver()
{
$this->app->config->set('auth.providers.canvas_users', [
'driver' => 'eloquent',
Expand All @@ -139,7 +139,7 @@ private function registerAuthDriver()
*
* @return void
*/
private function configurePublishing()
protected function configurePublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand Down
Loading

0 comments on commit 3c562a5

Please sign in to comment.