<commit_before><?php

namespace ApolloPY\Flysystem\AliyunOss;

use OSS\Http\ResponseCore;
use OSS\Http\RequestCore;
use OSS\OssClient;
use OSS\Core\OssException;
use League\Flysystem\Util;
use League\Flysystem\Config;
use League\Flysystem\Adapter\AbstractAdapter;
use League\Flysystem\Adapter\Polyfill\StreamedTrait;
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
use Illuminate\Http\Request;
use DateTime;
use Log;

/**
 * Aliyun Oss Adapter class.
 *
 * @author  ApolloPY <<EMAIL>>
 */
class AliyunOssAdapter extends AbstractAdapter
{
    use StreamedTrait;
    use NotSupportingVisibilityTrait;

    /**
     * Aliyun Oss Client.
     *
     * @var \OSS\OssClient
     */
    protected $client;

    /**
     * bucket name.
     *
     * @var string
     */
    protected $bucket;
    /**
     * host name.
     *
     * @var string
     */
    protected $host;

    /**
     * @var array
     */
    protected $options = [];

    /**
     * @var array
     */
    protected static $mappingOptions = [
        'mimetype' => OssClient::OSS_CONTENT_TYPE,
        'size'     => OssClient::OSS_LENGTH,
    ];

    /**
     * Constructor.
     *
     * @param OssClient $client
     * @param string    $bucket
     * @param string    $prefix
     * @param array     $options
     */
    public function __construct(OssClient $client, $bucket, $prefix = null, array $options = [])
    {
        $this->client = $client;
        $this->bucket = $bucket;
        $this->setPathPrefix($prefix);
        $this->options = array_merge($this->options, $options);
    }

    /**
     * Get the Aliyun Oss Client bucket.
     *
     * @param string $dir
     * @param bool $withHost
     *
     * @return array($bucket,$host)
     */
    public function getBucket($dir=null,$withHost=false)
    {
        if(!$dir){
            return $this->bucket;
        }
        //权限
        $public_dir  = config('filesystems.disks.oss.public');
        $private_dir = config('filesystems.disks.oss.private');
        $acl = 'public';
        if(in_array(explode('/',$dir)[0],$public_dir)){
            $acl = 'public';
        }elseif(in_array(explode('/',$dir)[0],$private_dir)){
            $acl = 'private';
        }
        //环境
        $bucket_key = 'filesystems.disks.oss.'.$acl.'_bucket';
        $host_key = 'filesystems.disks.oss.'.$acl.'_bucket';

        return $withHost ? [config($bucket_key),config($host_key)] : $bucket_key;
    }

    /**<commit_msg>增加host<commit_after><?php

namespace ApolloPY\Flysystem\AliyunOss;

use OSS\Http\ResponseCore;
use OSS\Http\RequestCore;
use OSS\OssClient;
use OSS\Core\OssException;
use League\Flysystem\Util;
use League\Flysystem\Config;
use League\Flysystem\Adapter\AbstractAdapter;
use League\Flysystem\Adapter\Polyfill\StreamedTrait;
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
use Illuminate\Http\Request;
use DateTime;
use Log;

/**
 * Aliyun Oss Adapter class.
 *
 * @author  ApolloPY <<EMAIL>>
 */
class AliyunOssAdapter extends AbstractAdapter
{
    use StreamedTrait;
    use NotSupportingVisibilityTrait;

    /**
     * Aliyun Oss Client.
     *
     * @var \OSS\OssClient
     */
    protected $client;

    /**
     * bucket name.
     *
     * @var string
     */
    protected $bucket;
    /**
     * host name.
     *
     * @var string
     */
    protected $host;

    /**
     * @var array
     */
    protected $options = [];

    /**
     * @var array
     */
    protected static $mappingOptions = [
        'mimetype' => OssClient::OSS_CONTENT_TYPE,
        'size'     => OssClient::OSS_LENGTH,
    ];

    /**
     * Constructor.
     *
     * @param OssClient $client
     * @param string    $bucket
     * @param string    $prefix
     * @param array     $options
     */
    public function __construct(OssClient $client, $bucket, $prefix = null, array $options = [])
    {
        $this->client = $client;
        $this->bucket = $bucket;
        $this->setPathPrefix($prefix);
        $this->options = array_merge($this->options, $options);
    }

    /**
     * Get the Aliyun Oss Client bucket.
     *
     * @param string $dir
     * @param bool $withHost
     *
     * @return array($bucket,$host)
     */
    public function getBucket($dir=null,$withHost=false)
    {
        if(!$dir){
            return $this->bucket;
        }
        //权限
        $public_dir  = config('filesystems.disks.oss.public');
        $private_dir = config('filesystems.disks.oss.private');
        $acl = 'public';
        if(in_array(explode('/',$dir)[0],$public_dir)){
            $acl = 'public';
        }elseif(in_array(explode('/',$dir)[0],$private_dir)){
            $acl = 'private';
        }
        //环境
        $bucket_key = 'filesystems.disks.oss.'.$acl.'_bucket';
        $host_key = 'filesystems.disks.oss.'.$acl.'_bucket_host';

        return $withHost ? [config($bucket_key),config($host_key)] : $bucket_key;
    }

    /**
{'fraction_non_alphanumeric': 0.145985401459854, 'fraction_numerical': 0.0008110300081103001, 'mean_word_length': 2.2733908427339085, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4087332', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1605, 'n_words': 292}