mirror of
https://github.com/friendica/friendica
synced 2025-04-28 11:44:23 +02:00
API: The media upload (audio, video) is now possible
This commit is contained in:
parent
e3c782010f
commit
7dc75d585e
9 changed files with 151 additions and 41 deletions
|
@ -245,6 +245,7 @@ class Attach
|
|||
* @param string $src Source file name
|
||||
* @param int $uid User id
|
||||
* @param string $filename Optional file name
|
||||
* @param string $filetype Optional file type
|
||||
* @param string $allow_cid
|
||||
* @param string $allow_gid
|
||||
* @param string $deny_cid
|
||||
|
@ -252,7 +253,7 @@ class Attach
|
|||
* @return boolean|int Insert id or false on failure
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function storeFile(string $src, int $uid, string $filename = '', string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '')
|
||||
public static function storeFile(string $src, int $uid, string $filename = '', string $filetype = '', string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '')
|
||||
{
|
||||
if ($filename === '') {
|
||||
$filename = basename($src);
|
||||
|
@ -260,7 +261,7 @@ class Attach
|
|||
|
||||
$data = @file_get_contents($src);
|
||||
|
||||
return self::store($data, $uid, $filename, '', null, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
|
||||
return self::store($data, $uid, $filename, $filetype, null, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,6 +346,16 @@ class Attach
|
|||
}
|
||||
}
|
||||
|
||||
public static function setPermissionForId(int $id, int $uid, string $str_contact_allow, string $str_circle_allow, string $str_contact_deny, string $str_circle_deny)
|
||||
{
|
||||
$fields = [
|
||||
'allow_cid' => $str_contact_allow, 'allow_gid' => $str_circle_allow,
|
||||
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_circle_deny,
|
||||
];
|
||||
|
||||
self::update($fields, ['id' => $id, 'uid' => $uid]);
|
||||
}
|
||||
|
||||
public static function addAttachmentToBody(string $body, int $uid): string
|
||||
{
|
||||
preg_match_all("/\[attachment\](.*?)\[\/attachment\]/ism", $body, $matches, PREG_SET_ORDER);
|
||||
|
|
|
@ -444,42 +444,46 @@ class Media
|
|||
return $data;
|
||||
}
|
||||
|
||||
$type = explode('/', current(explode(';', $data['mimetype'])));
|
||||
$data['type'] = self::getType($data['mimetype']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getType(string $mimeType): int
|
||||
{
|
||||
$type = explode('/', current(explode(';', $mimeType)));
|
||||
if (count($type) < 2) {
|
||||
Logger::info('Unknown MimeType', ['type' => $type, 'media' => $data]);
|
||||
$data['type'] = self::UNKNOWN;
|
||||
return $data;
|
||||
Logger::info('Unknown MimeType', ['type' => $type, 'media' => $mimeType]);
|
||||
return self::UNKNOWN;
|
||||
}
|
||||
|
||||
$filetype = strtolower($type[0]);
|
||||
$subtype = strtolower($type[1]);
|
||||
|
||||
if ($filetype == 'image') {
|
||||
$data['type'] = self::IMAGE;
|
||||
$type = self::IMAGE;
|
||||
} elseif ($filetype == 'video') {
|
||||
$data['type'] = self::VIDEO;
|
||||
$type = self::VIDEO;
|
||||
} elseif ($filetype == 'audio') {
|
||||
$data['type'] = self::AUDIO;
|
||||
$type = self::AUDIO;
|
||||
} elseif (($filetype == 'text') && ($subtype == 'html')) {
|
||||
$data['type'] = self::HTML;
|
||||
$type = self::HTML;
|
||||
} elseif (($filetype == 'text') && ($subtype == 'xml')) {
|
||||
$data['type'] = self::XML;
|
||||
$type = self::XML;
|
||||
} elseif (($filetype == 'text') && ($subtype == 'plain')) {
|
||||
$data['type'] = self::PLAIN;
|
||||
$type = self::PLAIN;
|
||||
} elseif ($filetype == 'text') {
|
||||
$data['type'] = self::TEXT;
|
||||
$type = self::TEXT;
|
||||
} elseif (($filetype == 'application') && ($subtype == 'x-bittorrent')) {
|
||||
$data['type'] = self::TORRENT;
|
||||
$type = self::TORRENT;
|
||||
} elseif ($filetype == 'application') {
|
||||
$data['type'] = self::APPLICATION;
|
||||
$type = self::APPLICATION;
|
||||
} else {
|
||||
$data['type'] = self::UNKNOWN;
|
||||
Logger::info('Unknown type', ['filetype' => $filetype, 'subtype' => $subtype, 'media' => $data]);
|
||||
return $data;
|
||||
$type = self::UNKNOWN;
|
||||
Logger::info('Unknown type', ['filetype' => $filetype, 'subtype' => $subtype, 'media' => $mimeType]);
|
||||
}
|
||||
|
||||
Logger::debug('Detected type', ['filetype' => $filetype, 'subtype' => $subtype, 'media' => $data]);
|
||||
return $data;
|
||||
Logger::debug('Detected type', ['filetype' => $filetype, 'subtype' => $subtype, 'media' => $mimeType]);
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue