99use function Takuya \Utils \base_domain ;
1010use function Takuya \Utils \parent_domain ;
1111use function Takuya \Utils \assert_str_is_domain ;
12+ use League \Flysystem \WebDAV \WebDAVAdapter ;
13+ use League \Flysystem \Filesystem ;
1214
1315class BacklogAPIClient {
1416
@@ -24,6 +26,36 @@ public function __construct( protected $spaceId_or_url, protected $key ) {
2426 [$ this ->space , $ this ->tld ] = $ this ->validateSpaceId ($ spaceId_or_url );
2527 $ this ->limiter = new RequestRateLimiter ();
2628 }
29+ public function addSharedFile ($ projectId ,$ path ,$ content , $ userName =null ,$ password =null ){
30+ $ user = $ userName ?? getenv ('BACKLOG_USER ' );
31+ $ pass = $ password ?? getenv ('BACKLOG_PASS ' );
32+ $ client = new \Sabre \DAV \Client ([
33+ 'baseUri ' => $ this ->getDavAddress ($ projectId ),
34+ 'userName ' => $ user ,
35+ 'password ' => $ pass
36+ ]);
37+ $ adapter = new WebDAVAdapter ($ client );
38+ $ filesystem = new Filesystem ($ adapter );
39+ $ filesystem ->write ($ path ,$ content );
40+ }
41+ public function getSharedFileId ( $ projectId ,$ path ){
42+ $ list = $ this ->getListOfSharedFiles ($ projectId ,'' );
43+ foreach ( $ list as $ item ) {
44+ if ($ path == $ item ->dir .DIRECTORY_SEPARATOR .$ item ->name ){
45+ return $ item ->id ;
46+ }
47+ }
48+ return null ;
49+ }
50+ public function getDavAddress (int |string $ project_id_or_key ){
51+ $ key = null ;
52+ if (is_int ($ project_id_or_key )){
53+ $ key = $ this ->getProject ($ project_id_or_key )->projectKey ;
54+ }else {
55+ $ key = $ project_id_or_key ;
56+ }
57+ return sprintf ('%s/dav/%s/ ' ,$ this ->base_uri (),$ key );
58+ }
2759
2860 protected function validateSpaceId ( string $ spaceId_or_url ):array {
2961 if ( str_starts_with ($ spaceId_or_url , 'http ' ) ) {
0 commit comments