Compare commits
1 Commits
e42c9f4d8f
...
1.0.0
Author | SHA1 | Date | |
---|---|---|---|
8648f5a62e |
@ -83,25 +83,16 @@ class Mailboxes
|
|||||||
$body = $request->getBody();
|
$body = $request->getBody();
|
||||||
$json = \Safe\json_decode($body->getContents());
|
$json = \Safe\json_decode($body->getContents());
|
||||||
if (!isset($json->mailboxes)) {
|
if (!isset($json->mailboxes)) {
|
||||||
throw new MissingArgument('mailboxes', 'array', 'mailboxes ids');
|
throw new MissingArgument('mailboxes', 'array', 'mailboxes names');
|
||||||
}
|
}
|
||||||
$output = [
|
$output = [
|
||||||
'mailboxes' => $json->mailboxes,
|
'mailboxes' => $json->mailboxes,
|
||||||
'total' => count($json->mailboxes),
|
'total' => count($json->mailboxes),
|
||||||
'unregistered' => [
|
'unregistered' => 0
|
||||||
'total' => 0,
|
|
||||||
'mailboxes' => []
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
foreach ($json->mailboxes as $mailbox_id) {
|
foreach ($json->mailboxes as $mailbox_name) {
|
||||||
$mailbox = $service->getRepository()->fetchById($mailbox_id);
|
if ($service->unregister($mailbox_name)) {
|
||||||
if ($service->unregister($mailbox->getName())) {
|
$output['unregistered'] ++;
|
||||||
$output['unregistered']['total'] ++;
|
|
||||||
$output['unregistered']['mailboxes'] []= [
|
|
||||||
'id' => $mailbox->getId(),
|
|
||||||
'name' => $mailbox->getName(),
|
|
||||||
'unregistered' => true
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
|
@ -118,7 +118,6 @@ class Mailboxes extends Base
|
|||||||
try {
|
try {
|
||||||
$mailbox = $this->getRepository()->fetchByName($mailbox_name);
|
$mailbox = $this->getRepository()->fetchByName($mailbox_name);
|
||||||
} catch (BlankResult $e) {
|
} catch (BlankResult $e) {
|
||||||
$this->getLogger()->error($e);
|
|
||||||
// It's already unregistered
|
// It's already unregistered
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ class Message implements Model
|
|||||||
|
|
||||||
public function doesHaveAttachments(): Message
|
public function doesHaveAttachments(): Message
|
||||||
{
|
{
|
||||||
if (!isset($this->getStates()['has_attachments'])) {
|
if (!isset($this->getState()['has_attachments'])) {
|
||||||
$this->newState('has_attachments');
|
$this->newState('has_attachments');
|
||||||
}
|
}
|
||||||
$this->getState('has_attachments')->setValue(true);
|
$this->getState('has_attachments')->setValue(true);
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace ProVM\Common\Controller;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use ProVM\Common\Service\Api as Service;
|
|
||||||
|
|
||||||
class Api
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface
|
|
||||||
{
|
|
||||||
$body = $request->getBody();
|
|
||||||
$json = \Safe\json_decode($body->getContents(), JSON_OBJECT_AS_ARRAY);
|
|
||||||
|
|
||||||
return $service->sendRequest($json);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace ProVM\Common\Service;
|
|
||||||
|
|
||||||
use Psr\Http\Client\ClientInterface;
|
|
||||||
use Psr\Http\Message\RequestFactoryInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
class Api
|
|
||||||
{
|
|
||||||
public function __construct(ClientInterface $client, RequestFactoryInterface $factory)
|
|
||||||
{
|
|
||||||
$this->setClient($client)
|
|
||||||
->setFactory($factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClientInterface $client;
|
|
||||||
protected RequestFactoryInterface $factory;
|
|
||||||
|
|
||||||
public function getClient(): ClientInterface
|
|
||||||
{
|
|
||||||
return $this->client;
|
|
||||||
}
|
|
||||||
public function getFactory(): RequestFactoryInterface
|
|
||||||
{
|
|
||||||
return $this->factory;
|
|
||||||
}
|
|
||||||
public function setClient(ClientInterface $client): Api
|
|
||||||
{
|
|
||||||
$this->client = $client;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
public function setFactory(RequestFactoryInterface $factory): Api
|
|
||||||
{
|
|
||||||
$this->factory = $factory;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sendRequest(array $request_data): ResponseInterface
|
|
||||||
{
|
|
||||||
$request = $this->getFactory()->createRequest(strtoupper($request_data['method']) ?? 'GET', $request_data['uri']);
|
|
||||||
if (strtolower($request_data['method']) !== 'get') {
|
|
||||||
$request->getBody()->write(\Safe\json_encode($request_data['data']));
|
|
||||||
$request->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
return $this->getClient()->sendRequest($request);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
<?php
|
|
||||||
use ProVM\Common\Controller\Api;
|
|
||||||
|
|
||||||
$app->post('/api', Api::class);
|
|
@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
use ProVM\Common\Controller\Home;
|
use ProVM\Common\Controller\Home;
|
||||||
|
|
||||||
$app->get('[/]', Home::class);
|
$app->get('[/]', Home::class);
|
@ -33,8 +33,8 @@
|
|||||||
).append(
|
).append(
|
||||||
$('<button></button>').addClass('ui mini circular red icon button').append(
|
$('<button></button>').addClass('ui mini circular red icon button').append(
|
||||||
$('<i></i>').addClass('remove icon')
|
$('<i></i>').addClass('remove icon')
|
||||||
).click(e => {
|
).click(() => {
|
||||||
this.unregister($(e.currentTarget))
|
this.unregister()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -42,7 +42,7 @@
|
|||||||
register.append(
|
register.append(
|
||||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||||
$('<i></i>').addClass('save icon')
|
$('<i></i>').addClass('save icon')
|
||||||
).click(e => {
|
).click((e) => {
|
||||||
this.register($(e.currentTarget))
|
this.register($(e.currentTarget))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -72,25 +72,20 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
unregister(button) {
|
unregister() {
|
||||||
const uri = '/mailboxes/unregister'
|
const uri = '/mailboxes/unregister'
|
||||||
const data = {
|
const data = {
|
||||||
mailboxes: [this.id]
|
mailboxes: [this.id]
|
||||||
}
|
}
|
||||||
button.html('').append(
|
|
||||||
$('<i></i>').addClass('redo loading icon')
|
|
||||||
)
|
|
||||||
return Send.delete({
|
return Send.delete({
|
||||||
uri,
|
uri,
|
||||||
data
|
data
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
response.unregistered.mailboxes.forEach(mb => {
|
response.mailboxes.forEach(mb => {
|
||||||
if (mb.id === this.id && mb.unregistered) {
|
if (mb.id === this.id && mb.removed) {
|
||||||
this.id = null
|
this.id = null
|
||||||
this.registered = false
|
this.registered = false
|
||||||
const tr = button.parent().parent()
|
mailboxes.draw().table()
|
||||||
tr.html('')
|
|
||||||
this.draw(tr)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -221,13 +221,7 @@
|
|||||||
},
|
},
|
||||||
messages: () => {
|
messages: () => {
|
||||||
const uri = '/mailbox/{{$mailbox_id}}/messages/valid'
|
const uri = '/mailbox/{{$mailbox_id}}/messages/valid'
|
||||||
return Send.get(uri).then((response, status, jqXHR) => {
|
return Send.get(uri).then(response => {
|
||||||
if (parseInt(jqXHR.status/100) !== 2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (jqXHR.status === 204) {
|
|
||||||
this.draw().empty()
|
|
||||||
}
|
|
||||||
if (this.total === null) {
|
if (this.total === null) {
|
||||||
$(this.id.count).html(' (' + response.total + ')')
|
$(this.id.count).html(' (' + response.total + ')')
|
||||||
this.total = response.total
|
this.total = response.total
|
||||||
@ -454,4 +448,4 @@
|
|||||||
messages.setup()
|
messages.setup()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
@ -1,33 +1,38 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const Send = {
|
const Send = {
|
||||||
base_url: '{{$urls->api}}',
|
base_url: '{{$urls->api}}',
|
||||||
base: function({method, uri, data = null}) {
|
base: function({method, uri, data = null, dataType = 'json', contentType = 'application/json'}) {
|
||||||
const request = {
|
const url = this.base_url + '/' + uri.replace(/^\//g, '')
|
||||||
uri: uri.replace(/^\//g, ''),
|
|
||||||
method
|
|
||||||
}
|
|
||||||
const options = {
|
const options = {
|
||||||
url: this.base_url,
|
method,
|
||||||
method: 'post',
|
url,
|
||||||
contentType: 'application/json'
|
crossDomain: true,
|
||||||
|
headers: {
|
||||||
|
'Authorization': [
|
||||||
|
'Bearer {{$api_key}}'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
dataType
|
||||||
}
|
}
|
||||||
if (method.toLowerCase() !== 'get' && data !== null) {
|
if (method.toLowerCase() !== 'get' && data !== null) {
|
||||||
request['data'] = data
|
if (!(typeof data === 'string' || data instanceof String)) {
|
||||||
|
options['data'] = JSON.stringify(data)
|
||||||
|
}
|
||||||
|
options['contentType'] = contentType
|
||||||
}
|
}
|
||||||
options['data'] = JSON.stringify(request)
|
|
||||||
return $.ajax(options)
|
return $.ajax(options)
|
||||||
},
|
},
|
||||||
get: function(uri) {
|
get: function(uri, dataType = 'json') {
|
||||||
return this.base({method: 'get', uri})
|
return this.base({method: 'get', uri, dataType})
|
||||||
},
|
},
|
||||||
post: function({uri, data}) {
|
post: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||||
return this.base({method: 'post', uri, data})
|
return this.base({method: 'post', uri, data, dataType, contentType})
|
||||||
},
|
},
|
||||||
put: function({uri, data}) {
|
put: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||||
return this.base({method: 'put', uri, data})
|
return this.base({method: 'put', uri, data, dataType, contentType})
|
||||||
},
|
},
|
||||||
delete: function({uri, data}) {
|
delete: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||||
return this.base({method: 'delete', uri, data})
|
return this.base({method: 'delete', uri, data, dataType, contentType})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
|
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
|
||||||
|
@ -2,12 +2,7 @@
|
|||||||
return [
|
return [
|
||||||
'urls' => function() {
|
'urls' => function() {
|
||||||
$arr = ['base' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']];
|
$arr = ['base' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']];
|
||||||
$arr['api'] = $_ENV['API_URI'];
|
$arr['api'] = 'http://localhost:8080';
|
||||||
return (object) $arr;
|
return (object) $arr;
|
||||||
},
|
}
|
||||||
'view_urls' => function() {
|
|
||||||
$arr = ['base' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']];
|
|
||||||
$arr['api'] = implode('/', [$arr['base'], 'api']);
|
|
||||||
return (object) $arr;
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
@ -11,8 +11,5 @@ return [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
},
|
}
|
||||||
Psr\Http\Message\RequestFactoryInterface::class => function(ContainerInterface $container) {
|
|
||||||
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
|
|
||||||
},
|
|
||||||
];
|
];
|
@ -2,13 +2,13 @@
|
|||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Slim\Views\Blade::class => function(ContainerInterface $container) {
|
\Slim\Views\Blade::class => function(ContainerInterface $container) {
|
||||||
return new Slim\Views\Blade(
|
return new \Slim\Views\Blade(
|
||||||
$container->get('folders')->views,
|
$container->get('folders')->views,
|
||||||
$container->get('folders')->cache,
|
$container->get('folders')->cache,
|
||||||
null,
|
null,
|
||||||
[
|
[
|
||||||
'urls' => $container->get('view_urls'),
|
'urls' => $container->get('urls'),
|
||||||
'api_key' => $container->get('api_key')
|
'api_key' => $container->get('api_key')
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user